Skip to content

Commit

Permalink
Improve ruff config (#15516)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Jun 28, 2023
1 parent 4d94271 commit 4012c50
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
# We also run these checks with pre-commit in CI,
# but it's useful to run them with tox too,
# to ensure the tox env works as expected
- name: Formatting with Black + isort and code style with ruff
- name: Formatting and code style with Black + ruff
python: '3.10'
arch: x64
os: ubuntu-latest
Expand Down
5 changes: 1 addition & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ repos:
rev: 23.3.0 # must match test-requirements.txt
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0 # must match test-requirements.txt
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.272 # must match test-requirements.txt
hooks:
- id: ruff
args: [--exit-non-zero-on-fix]
11 changes: 2 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,8 @@ pytest -n0 -k 'test_name'
# Run all test cases in the "test-data/unit/check-dataclasses.test" file
pytest mypy/test/testcheck.py::TypeCheckSuite::check-dataclasses.test

# Run the linter
ruff .

# Run formatters
black . && isort .
# Run the formatters and linters
python runtests.py lint
```

For an in-depth guide on running and writing tests,
Expand Down Expand Up @@ -154,10 +151,6 @@ advice about good pull requests for open-source projects applies; we
have [our own writeup](https://github.com/python/mypy/wiki/Good-Pull-Request)
of this advice.

We are using `black` and `isort` to enforce a consistent coding style.
Run `black . && isort .` before your commits, otherwise you would receive
a CI failure.

Also, do not squash your commits after you have submitted a pull request, as this
erases context during review. We will squash commits when the pull request is merged.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Mypy: Static Typing for Python
[![Chat at https://gitter.im/python/typing](https://badges.gitter.im/python/typing.svg)](https://gitter.im/python/typing?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
[![Linting: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

Got a question?
---------------
Expand Down
2 changes: 1 addition & 1 deletion mypy/copytype.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
)

# type_visitor needs to be imported after types
from mypy.type_visitor import TypeVisitor # isort: skip
from mypy.type_visitor import TypeVisitor # ruff: isort: skip


def copy_type(t: ProperType) -> ProperType:
Expand Down
30 changes: 15 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,18 @@ force-exclude = '''
^/test-data
'''

[tool.isort]
py_version = 37
profile = "black"
line_length = 99
combine_as_imports = true
skip_gitignore = true
extra_standard_library = ["typing_extensions"]
skip_glob = [
"mypy/typeshed/*",
"mypyc/test-data/*",
"test-data/*",
]

[tool.ruff]
line-length = 99
target-version = "py37"
fix = true

select = [
"E", # pycoderstyle (error)
"E", # pycodestyle (error)
"F", # pyflakes
"B", # flake8-bugbear
"I", # isort
"RUF100", # Unused noqa comments
"PGH004" # blanket noqa comments
"PGH004" # blanket noqa comments
]

ignore = [
Expand All @@ -64,6 +53,13 @@ ignore = [
"E741", # Ambiguous variable name
]

unfixable = [
"F841", # unused variable. ruff keeps the call, but mostly we want to get rid of it all
"F601", # automatic fix might obscure issue
"F602", # automatic fix might obscure issue
"B018", # automatic fix might obscure issue
]

extend-exclude = [
"@*",
# Sphinx configuration is irrelevant
Expand All @@ -77,5 +73,9 @@ extend-exclude = [
"mypy/typeshed/*",
]

[tool.ruff.isort]
combine-as-imports = true
extra-standard-library = ["typing_extensions"]

[tool.check-manifest]
ignore = ["**/.readthedocs.yaml"]
1 change: 0 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
attrs>=18.0
black==23.3.0 # must match version in .pre-commit-config.yaml
filelock>=3.3.0
isort[colors]==5.12.0; python_version >= "3.8" # must match version in .pre-commit-config.yaml
lxml>=4.9.1; (python_version<'3.11' or sys_platform!='win32') and python_version<'3.12'
pre-commit
pre-commit-hooks==4.4.0
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ commands =
[testenv:lint]
description = check the code style
skip_install = true
deps = pre-commit
commands = pre-commit run --all-files --show-diff-on-failure

[testenv:type]
Expand Down

0 comments on commit 4012c50

Please sign in to comment.