Skip to content

Commit 304997b

Browse files
authored
Switch from flake8 to ruff (python#15362)
1 parent e3210d0 commit 304997b

File tree

15 files changed

+52
-92
lines changed

15 files changed

+52
-92
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
# We also run these checks with pre-commit in CI,
9797
# but it's useful to run them with tox too,
9898
# to ensure the tox env works as expected
99-
- name: Formatting with Black + isort and code style with flake8
99+
- name: Formatting with Black + isort and code style with ruff
100100
python: '3.10'
101101
arch: x64
102102
os: ubuntu-latest

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,5 @@ test_capi
5757
*.o
5858
*.a
5959
test_capi
60-
/.mypyc-flake8-cache.json
6160
/mypyc/lib-rt/build/
6261
/mypyc/lib-rt/*.so

.pre-commit-config.yaml

+3-10
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@ repos:
1313
rev: 5.12.0 # must match test-requirements.txt
1414
hooks:
1515
- id: isort
16-
- repo: https://github.com/pycqa/flake8
17-
rev: 6.0.0 # must match test-requirements.txt
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
rev: v0.0.272 # must match test-requirements.txt
1818
hooks:
19-
- id: flake8
20-
additional_dependencies:
21-
- flake8-bugbear==23.3.23 # must match test-requirements.txt
22-
- flake8-noqa==1.3.1 # must match test-requirements.txt
23-
24-
ci:
25-
# We run flake8 as part of our GitHub Actions suite in CI
26-
skip: [flake8]
19+
- id: ruff

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pytest -n0 -k 'test_name'
8989
pytest mypy/test/testcheck.py::TypeCheckSuite::check-dataclasses.test
9090

9191
# Run the linter
92-
flake8
92+
ruff .
9393

9494
# Run formatters
9595
black . && isort .

mypy/build.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3076,7 +3076,7 @@ def load_graph(
30763076
manager.errors.report(
30773077
-1,
30783078
-1,
3079-
"See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules " # noqa: E501
3079+
"See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules "
30803080
"for more info",
30813081
severity="note",
30823082
)
@@ -3164,7 +3164,7 @@ def load_graph(
31643164
manager.errors.report(
31653165
-1,
31663166
0,
3167-
"See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules " # noqa: E501
3167+
"See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules "
31683168
"for more info",
31693169
severity="note",
31703170
)

mypy/plugins/common.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
require_bool_literal_argument,
2929
set_callable_name,
3030
)
31-
from mypy.typeops import ( # noqa: F401 # Part of public API
32-
try_getting_str_literals as try_getting_str_literals,
33-
)
31+
from mypy.typeops import try_getting_str_literals as try_getting_str_literals
3432
from mypy.types import (
3533
AnyType,
3634
CallableType,

mypy/server/objgraph.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def get_edge_candidates(o: object) -> Iterator[tuple[object, object]]:
4646
try:
4747
if attr not in ATTR_BLACKLIST and hasattr(o, attr) and not isproperty(o, attr):
4848
e = getattr(o, attr)
49-
if not type(e) in ATOMIC_TYPE_BLACKLIST:
49+
if type(e) not in ATOMIC_TYPE_BLACKLIST:
5050
yield attr, e
5151
except AssertionError:
5252
pass
@@ -70,7 +70,7 @@ def get_edges(o: object) -> Iterator[tuple[object, object]]:
7070
if se is not o and se is not type(o) and hasattr(s, "__self__"):
7171
yield s.__self__, se
7272
else:
73-
if not type(e) in TYPE_BLACKLIST:
73+
if type(e) not in TYPE_BLACKLIST:
7474
yield s, e
7575

7676

mypy/typeanal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ def analyze_callable_type(self, t: UnboundType) -> Type:
12561256
code=codes.VALID_TYPE,
12571257
)
12581258
self.note(
1259-
"See https://mypy.readthedocs.io/en/stable/kinds_of_types.html#callable-types-and-lambdas", # noqa: E501
1259+
"See https://mypy.readthedocs.io/en/stable/kinds_of_types.html#callable-types-and-lambdas",
12601260
t,
12611261
)
12621262
return AnyType(TypeOfAny.from_error)

mypy/types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2957,7 +2957,7 @@ def get_proper_types(
29572957
# to make it easier to gradually get modules working with mypyc.
29582958
# Import them here, after the types are defined.
29592959
# This is intended as a re-export also.
2960-
from mypy.type_visitor import ( # noqa: F811,F401
2960+
from mypy.type_visitor import ( # noqa: F811
29612961
ALL_STRATEGY as ALL_STRATEGY,
29622962
ANY_STRATEGY as ANY_STRATEGY,
29632963
BoolTypeQuery as BoolTypeQuery,

mypyc/irbuild/specialize.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def translate_sum_call(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> V
446446
# handle 'start' argument, if given
447447
if len(expr.args) == 2:
448448
# ensure call to sum() was properly constructed
449-
if not expr.arg_kinds[1] in (ARG_POS, ARG_NAMED):
449+
if expr.arg_kinds[1] not in (ARG_POS, ARG_NAMED):
450450
return None
451451
start_expr = expr.args[1]
452452
else:

pyproject.toml

+37
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,40 @@ skip_glob = [
3939
"mypyc/test-data/*",
4040
"test-data/*",
4141
]
42+
43+
[tool.ruff]
44+
line-length = 99
45+
target-version = "py37"
46+
47+
select = [
48+
"E", # pycoderstyle (error)
49+
"F", # pyflakes
50+
"B", # flake8-bugbear
51+
"RUF100", # Unused noqa comments
52+
"PGH004" # blanket noqa comments
53+
]
54+
55+
ignore = [
56+
"B006", # use of mutable defaults in function signatures
57+
"B007", # Loop control variable not used within the loop body.
58+
"B011", # Don't use assert False
59+
"B023", # Function definition does not bind loop variable
60+
"E203", # conflicts with black
61+
"E402", # module level import not at top of file
62+
"E501", # conflicts with black
63+
"E731", # Do not assign a `lambda` expression, use a `def`
64+
"E741", # Ambiguous variable name
65+
]
66+
67+
extend-exclude = [
68+
"@*",
69+
# Sphinx configuration is irrelevant
70+
"docs/source/conf.py",
71+
"mypyc/doc/conf.py",
72+
# tests have more relaxed styling requirements
73+
# fixtures have their own .pyi-specific configuration
74+
"test-data/*",
75+
"mypyc/test-data/*",
76+
# typeshed has its own .pyi-specific configuration
77+
"mypy/typeshed/*",
78+
]

setup.cfg

-43
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,3 @@
1-
[flake8]
2-
max-line-length = 99
3-
noqa-require-code = True
4-
# typeshed and unit test fixtures have .pyi-specific flake8 configuration
5-
exclude =
6-
# from .gitignore: directories, and file patterns that intersect with *.py
7-
build,
8-
bin,
9-
lib,
10-
include,
11-
@*,
12-
env,
13-
docs/build,
14-
out,
15-
.venv,
16-
.mypy_cache,
17-
.git,
18-
.cache,
19-
# Sphinx configuration is irrelevant
20-
docs/source/conf.py,
21-
mypyc/doc/conf.py,
22-
# tests have more relaxed styling requirements
23-
# fixtures have their own .pyi-specific configuration
24-
test-data/*,
25-
mypyc/test-data/*,
26-
# typeshed has its own .pyi-specific configuration
27-
mypy/typeshed/*,
28-
.tox
29-
.eggs
30-
.Python
31-
32-
# Things to ignore:
33-
# E203: conflicts with black
34-
# E501: conflicts with black
35-
# W601: has_key() deprecated (false positives)
36-
# E402: module level import not at top of file
37-
# B006: use of mutable defaults in function signatures
38-
# B007: Loop control variable not used within the loop body.
39-
# B011: Don't use assert False
40-
# B023: Function definition does not bind loop variable
41-
# E741: Ambiguous variable name
42-
extend-ignore = E203,E501,W601,E402,B006,B007,B011,B023,E741
43-
441
[coverage:run]
452
branch = true
463
source = mypy

test-data/.flake8

-22
This file was deleted.

test-data/unit/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ To run mypy on itself:
159159

160160
To run the linter:
161161

162-
flake8
162+
ruff .
163163

164164
You can also run all of the above tests using `runtests.py` (this includes
165165
type checking mypy and linting):

test-requirements.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
attrs>=18.0
44
black==23.3.0 # must match version in .pre-commit-config.yaml
55
filelock>=3.3.0
6-
flake8==6.0.0; python_version >= "3.8" # must match version in .pre-commit-config.yaml
7-
flake8-bugbear==23.3.23; python_version >= "3.8" # must match version in .pre-commit-config.yaml
8-
flake8-noqa==1.3.1; python_version >= "3.8" # must match version in .pre-commit-config.yaml
96
isort[colors]==5.12.0; python_version >= "3.8" # must match version in .pre-commit-config.yaml
107
lxml>=4.9.1; (python_version<'3.11' or sys_platform!='win32') and python_version<'3.12'
118
pre-commit
@@ -17,6 +14,7 @@ pytest-xdist>=1.34.0
1714
pytest-forked>=1.3.0,<2.0.0
1815
pytest-cov>=2.10.0
1916
py>=1.5.2
17+
ruff==0.0.272 # must match version in .pre-commit-config.yaml
2018
setuptools>=65.5.1
2119
six
2220
tomli>=1.1.0

0 commit comments

Comments
 (0)