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

[Tooling] Switch from flake8 to ruff #15362

Merged
merged 8 commits into from
Jun 20, 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 flake8
- name: Formatting with Black + isort and code style with ruff
python: '3.10'
arch: x64
os: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,5 @@ test_capi
*.o
*.a
test_capi
/.mypyc-flake8-cache.json
/mypyc/lib-rt/build/
/mypyc/lib-rt/*.so
13 changes: 3 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ repos:
rev: 5.12.0 # must match test-requirements.txt
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 6.0.0 # must match test-requirements.txt
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.270 # must match test-requirements.txt
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==23.3.23 # must match test-requirements.txt
- flake8-noqa==1.3.1 # must match test-requirements.txt

ci:
# We run flake8 as part of our GitHub Actions suite in CI
skip: [flake8]
- id: ruff
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pytest -n0 -k 'test_name'
pytest mypy/test/testcheck.py::TypeCheckSuite::check-dataclasses.test

# Run the linter
flake8
ruff .

# Run formatters
black . && isort .
Expand Down
4 changes: 2 additions & 2 deletions mypy/server/objgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_edge_candidates(o: object) -> Iterator[tuple[object, object]]:
try:
if attr not in ATTR_BLACKLIST and hasattr(o, attr) and not isproperty(o, attr):
e = getattr(o, attr)
if not type(e) in ATOMIC_TYPE_BLACKLIST:
if type(e) not in ATOMIC_TYPE_BLACKLIST:
yield attr, e
except AssertionError:
pass
Expand All @@ -70,7 +70,7 @@ def get_edges(o: object) -> Iterator[tuple[object, object]]:
if se is not o and se is not type(o) and hasattr(s, "__self__"):
yield s.__self__, se
else:
if not type(e) in TYPE_BLACKLIST:
if type(e) not in TYPE_BLACKLIST:
yield s, e


Expand Down
2 changes: 1 addition & 1 deletion mypyc/irbuild/specialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def translate_sum_call(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> V
# handle 'start' argument, if given
if len(expr.args) == 2:
# ensure call to sum() was properly constructed
if not expr.arg_kinds[1] in (ARG_POS, ARG_NAMED):
if expr.arg_kinds[1] not in (ARG_POS, ARG_NAMED):
return None
start_expr = expr.args[1]
else:
Expand Down
36 changes: 36 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,39 @@ skip_glob = [
"mypyc/test-data/*",
"test-data/*",
]

[tool.ruff]
line-length = 99
dosisod marked this conversation as resolved.
Show resolved Hide resolved

extend-ignore = [
"B006", # use of mutable defaults in function signatures
dosisod marked this conversation as resolved.
Show resolved Hide resolved
"B007", # Loop control variable not used within the loop body.
"B011", # Don't use assert False
"B023", # Function definition does not bind loop variable
"E203", # conflicts with black
"E402", # module level import not at top of file
"E501", # conflicts with black
"E731", # Do not assign a `lambda` expression, use a `def`
"E741", # Ambiguous variable name
]

extend-exclude = [
"@*",
# Sphinx configuration is irrelevant
"docs/source/conf.py",
"mypyc/doc/conf.py",
# tests have more relaxed styling requirements
# fixtures have their own .pyi-specific configuration
"test-data/*",
"mypyc/test-data/*",
# typeshed has its own .pyi-specific configuration
"mypy/typeshed/*",
]

[tool.ruff.per-file-ignores]
dosisod marked this conversation as resolved.
Show resolved Hide resolved

"test-data/*" = [
"F401", # imported but unused
"F811", # redefinition
"E701", # multiple statements on one line (colon)
]
43 changes: 0 additions & 43 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,46 +1,3 @@
[flake8]
max-line-length = 99
noqa-require-code = True
# typeshed and unit test fixtures have .pyi-specific flake8 configuration
exclude =
# from .gitignore: directories, and file patterns that intersect with *.py
build,
bin,
lib,
include,
@*,
env,
docs/build,
out,
.venv,
.mypy_cache,
.git,
.cache,
# Sphinx configuration is irrelevant
docs/source/conf.py,
mypyc/doc/conf.py,
# tests have more relaxed styling requirements
# fixtures have their own .pyi-specific configuration
test-data/*,
mypyc/test-data/*,
# typeshed has its own .pyi-specific configuration
mypy/typeshed/*,
.tox
.eggs
.Python

# Things to ignore:
# E203: conflicts with black
# E501: conflicts with black
# W601: has_key() deprecated (false positives)
# E402: module level import not at top of file
# B006: use of mutable defaults in function signatures
# B007: Loop control variable not used within the loop body.
# B011: Don't use assert False
# B023: Function definition does not bind loop variable
# E741: Ambiguous variable name
extend-ignore = E203,E501,W601,E402,B006,B007,B011,B023,E741

[coverage:run]
branch = true
source = mypy
Expand Down
22 changes: 0 additions & 22 deletions test-data/.flake8

This file was deleted.

2 changes: 1 addition & 1 deletion test-data/unit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ To run mypy on itself:

To run the linter:

flake8
ruff .

You can also run all of the above tests using `runtests.py` (this includes
type checking mypy and linting):
Expand Down
4 changes: 1 addition & 3 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
attrs>=18.0
black==23.3.0 # must match version in .pre-commit-config.yaml
filelock>=3.3.0
flake8==6.0.0; python_version >= "3.8" # must match version in .pre-commit-config.yaml
flake8-bugbear==23.3.23; python_version >= "3.8" # must match version in .pre-commit-config.yaml
flake8-noqa==1.3.1; python_version >= "3.8" # must match version in .pre-commit-config.yaml
dosisod marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -17,6 +14,7 @@ pytest-xdist>=1.34.0
pytest-forked>=1.3.0,<2.0.0
pytest-cov>=2.10.0
py>=1.5.2
ruff==0.0.270 # must match version in .pre-commit-config.yaml
setuptools>=65.5.1
six
tomli>=1.1.0