Skip to content

Commit

Permalink
Switch from flake8 to ruff (#15362)
Browse files Browse the repository at this point in the history
  • Loading branch information
dosisod committed Jun 20, 2023
1 parent e3210d0 commit 304997b
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 92 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 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.272 # 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/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3076,7 +3076,7 @@ def load_graph(
manager.errors.report(
-1,
-1,
"See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules " # noqa: E501
"See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules "
"for more info",
severity="note",
)
Expand Down Expand Up @@ -3164,7 +3164,7 @@ def load_graph(
manager.errors.report(
-1,
0,
"See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules " # noqa: E501
"See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules "
"for more info",
severity="note",
)
Expand Down
4 changes: 1 addition & 3 deletions mypy/plugins/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
require_bool_literal_argument,
set_callable_name,
)
from mypy.typeops import ( # noqa: F401 # Part of public API
try_getting_str_literals as try_getting_str_literals,
)
from mypy.typeops import try_getting_str_literals as try_getting_str_literals
from mypy.types import (
AnyType,
CallableType,
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 mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ def analyze_callable_type(self, t: UnboundType) -> Type:
code=codes.VALID_TYPE,
)
self.note(
"See https://mypy.readthedocs.io/en/stable/kinds_of_types.html#callable-types-and-lambdas", # noqa: E501
"See https://mypy.readthedocs.io/en/stable/kinds_of_types.html#callable-types-and-lambdas",
t,
)
return AnyType(TypeOfAny.from_error)
Expand Down
2 changes: 1 addition & 1 deletion mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2957,7 +2957,7 @@ def get_proper_types(
# to make it easier to gradually get modules working with mypyc.
# Import them here, after the types are defined.
# This is intended as a re-export also.
from mypy.type_visitor import ( # noqa: F811,F401
from mypy.type_visitor import ( # noqa: F811
ALL_STRATEGY as ALL_STRATEGY,
ANY_STRATEGY as ANY_STRATEGY,
BoolTypeQuery as BoolTypeQuery,
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
37 changes: 37 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,40 @@ skip_glob = [
"mypyc/test-data/*",
"test-data/*",
]

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

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

ignore = [
"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
"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/*",
]
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
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.272 # must match version in .pre-commit-config.yaml
setuptools>=65.5.1
six
tomli>=1.1.0

0 comments on commit 304997b

Please sign in to comment.