Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ruff config #15516

Merged
merged 5 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ 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
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
hooks:
Expand Down
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 @@ -76,3 +72,7 @@ extend-exclude = [
# typeshed has its own .pyi-specific configuration
"mypy/typeshed/*",
]

[tool.ruff.isort]
combine-as-imports = true
extra-standard-library = ["typing_extensions"]
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
Loading