Skip to content

Commit ce07459

Browse files
Upgrade pre-commit configuration and move to ruff (#2057)
1 parent 886da70 commit ce07459

14 files changed

+55
-67
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,12 @@ repos:
99
exclude: .github/|tests/testdata
1010
- id: end-of-file-fixer
1111
exclude: tests/testdata
12-
- repo: https://github.com/PyCQA/autoflake
13-
rev: v2.0.2
12+
- repo: https://github.com/charliermarsh/ruff-pre-commit
13+
rev: "v0.0.255"
1414
hooks:
15-
- id: autoflake
16-
exclude: tests/testdata|astroid/__init__.py|astroid/scoped_nodes.py|astroid/node_classes.py
17-
args:
18-
- --in-place
19-
- --remove-all-unused-imports
20-
- --expand-star-imports
21-
- --remove-duplicate-keys
22-
- --remove-unused-variables
15+
- id: ruff
16+
exclude: tests/testdata
17+
args: ["--fix"]
2318
- repo: https://github.com/Pierre-Sassoulas/copyright_notice_precommit
2419
rev: 0.1.2
2520
hooks:
@@ -33,11 +28,6 @@ repos:
3328
- id: pyupgrade
3429
exclude: tests/testdata
3530
args: [--py37-plus]
36-
- repo: https://github.com/PyCQA/isort
37-
rev: 5.12.0
38-
hooks:
39-
- id: isort
40-
exclude: tests/testdata
4131
- repo: https://github.com/Pierre-Sassoulas/black-disable-checker/
4232
rev: v1.1.3
4333
hooks:
@@ -49,13 +39,6 @@ repos:
4939
- id: black
5040
args: [--safe, --quiet]
5141
exclude: tests/testdata
52-
- repo: https://github.com/PyCQA/flake8
53-
rev: 6.0.0
54-
hooks:
55-
- id: flake8
56-
additional_dependencies:
57-
[flake8-bugbear==23.2.13, flake8-typing-imports==1.14.0]
58-
exclude: tests/testdata|doc/conf.py
5942
- repo: local
6043
hooks:
6144
- id: pylint

astroid/brain/brain_dataclasses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def _generate_dataclass_init( # pylint: disable=too-many-locals
360360
if name in prev_pos_only_store:
361361
prev_pos_only_store[name] = (ann_str, default_str)
362362
elif name in prev_kw_only_store:
363-
params = [name] + params
363+
params = [name, *params]
364364
prev_kw_only_store.pop(name)
365365
else:
366366
params.append(param_str)

astroid/brain/brain_namedtuple_enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def _check_namedtuple_attributes(typename, attributes, rename=False):
284284

285285
# The following snippet is derived from the CPython Lib/collections/__init__.py sources
286286
# <snippet>
287-
for name in (typename,) + attributes:
287+
for name in (typename, *attributes):
288288
if not isinstance(name, str):
289289
raise AstroidTypeError("Type names and field names must be strings")
290290
if not name.isidentifier():

astroid/interpreter/_import/spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def find_module(
230230
submodule_path: Sequence[str] | None,
231231
) -> ModuleSpec | None:
232232
if processed:
233-
modname = ".".join(processed + [modname])
233+
modname = ".".join([*processed, modname])
234234
if util.is_namespace(modname) and modname in sys.modules:
235235
submodule_path = sys.modules[modname].__path__
236236
return ModuleSpec(

astroid/modutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ def _has_init(directory: str) -> str | None:
672672
else return None.
673673
"""
674674
mod_or_pack = os.path.join(directory, "__init__")
675-
for ext in PY_SOURCE_EXTS + ("pyc", "pyo"):
675+
for ext in (*PY_SOURCE_EXTS, "pyc", "pyo"):
676676
if os.path.exists(mod_or_pack + "." + ext):
677677
return mod_or_pack + "." + ext
678678
return None

astroid/nodes/node_classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ def get_children(self):
12731273

12741274
@cached_property
12751275
def _assign_nodes_in_scope(self) -> list[nodes.Assign]:
1276-
return [self] + self.value._assign_nodes_in_scope
1276+
return [self, *self.value._assign_nodes_in_scope]
12771277

12781278
def _get_yield_nodes_skip_lambdas(self):
12791279
yield from self.value._get_yield_nodes_skip_lambdas()

astroid/nodes/scoped_nodes/scoped_nodes.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
from functools import lru_cache
2020
from typing import TYPE_CHECKING, ClassVar, NoReturn, TypeVar, overload
2121

22-
from astroid import bases
22+
from astroid import bases, util
2323
from astroid import decorators as decorators_mod
24-
from astroid import util
2524
from astroid.const import IS_PYPY, PY38, PY38_PLUS, PY39_PLUS, PYPY_7_3_11_PLUS
2625
from astroid.context import (
2726
CallContext,
@@ -2927,7 +2926,7 @@ def _slots(self):
29272926
if exc.args and exc.args[0] not in ("", None):
29282927
return exc.args[0]
29292928
return None
2930-
return [first] + list(slots)
2929+
return [first, *slots]
29312930

29322931
# Cached, because inferring them all the time is expensive
29332932
@decorators_mod.cached
@@ -3033,7 +3032,7 @@ def _compute_mro(self, context: InferenceContext | None = None):
30333032
ancestors = list(base.ancestors(context=context))
30343033
bases_mro.append(ancestors)
30353034

3036-
unmerged_mro = [[self]] + bases_mro + [inferred_bases]
3035+
unmerged_mro = [[self], *bases_mro, inferred_bases]
30373036
unmerged_mro = list(clean_duplicates_mro(unmerged_mro, self, context))
30383037
clean_typing_generic_mro(unmerged_mro)
30393038
return _c3_merge(unmerged_mro, self, context)

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
# built documents.
6363
#
6464
# The short X.Y version.
65-
from astroid.__pkginfo__ import __version__
65+
from astroid.__pkginfo__ import __version__ # noqa
6666

6767
# The full version, including alpha/beta/rc tags.
6868
release = __version__

pyproject.toml

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ python_files = ["*test_*.py"]
6565
testpaths = ["tests"]
6666
filterwarnings = "error"
6767

68-
[tool.isort]
69-
include_trailing_comma = true
70-
known_first_party = ["astroid"]
71-
known_third_party = ["attr", "nose", "numpy", "pytest", "six", "sphinx"]
72-
line_length = 88
73-
multi_line_output = 3
74-
skip_glob = ["tests/testdata"]
75-
7668
[tool.mypy]
7769
enable_error_code = "ignore-without-code"
7870
no_implicit_optional = true
@@ -94,3 +86,36 @@ module = [
9486
"wrapt.*",
9587
]
9688
ignore_missing_imports = true
89+
90+
91+
[tool.ruff]
92+
93+
# ruff is less lenient than pylint and does not make any exceptions
94+
# (for docstrings, strings and comments in particular).
95+
line-length = 110
96+
97+
select = [
98+
"E", # pycodestyle
99+
"F", # pyflakes
100+
"W", # pycodestyle
101+
"B", # bugbear
102+
"I", # isort
103+
"RUF", # ruff
104+
]
105+
106+
ignore = [
107+
"B905", # `zip()` without an explicit `strict=` parameter
108+
"F401", # API
109+
"RUF100", # ruff does not understand pylint's directive usefulness
110+
]
111+
112+
fixable = [
113+
"E", # pycodestyle
114+
"F", # pyflakes
115+
"W", # pycodestyle
116+
"B", # bugbear
117+
"I", # isort
118+
"RUF", # ruff
119+
]
120+
unfixable = []
121+
target-version = "py37"

requirements_test_pre_commit.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
-r requirements_test_min.txt
2-
black==23.1.0
3-
pylint==2.17.0
4-
isort==5.12.0;python_version>='3.8'
5-
flake8==6.0.0;python_version>='3.8'
6-
flake8-typing-imports==1.14.0;python_version>='3.8'
7-
flake8-bugbear==23.2.13;python_version>='3.8'
8-
mypy==1.1.1
9-
pre-commit~=2.21
2+
black
3+
pylint
4+
mypy
5+
ruff
6+
pre-commit

setup.cfg

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,3 @@
77
license_files =
88
LICENSE
99
CONTRIBUTORS.txt
10-
11-
[flake8]
12-
# F401; Unused imports
13-
# E203; Incompatible with black see https://github.com/psf/black/issues/315
14-
# W503; Incompatible with black
15-
# B901; Combine yield and return statements in one function
16-
# B905; We still support python 3.9
17-
# B906; Flake8 plugin specific check that is always going to be a false positive in pylint
18-
# B907; Not worth a refactor
19-
extend-ignore = F401, E203, W503, B901, B905, B906, B907
20-
max-line-length = 110
21-
select = B,C,E,F,W,T4,B9
22-
# Required for flake8-typing-imports (v1.12.0)
23-
# The plugin doesn't yet read the value from pyproject.toml
24-
min_python_version = 3.7.2

tests/test_inference.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
import pytest
1919

20-
from astroid import Slice, arguments
20+
from astroid import Slice, arguments, helpers, nodes, objects, test_utils, util
2121
from astroid import decorators as decoratorsmod
22-
from astroid import helpers, nodes, objects, test_utils, util
2322
from astroid.arguments import CallSite
2423
from astroid.bases import BoundMethod, Instance, UnboundMethod, UnionType
2524
from astroid.builder import AstroidBuilder, _extract_single_node, extract_node, parse

tests/test_nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ def parse_transform(self, code: str) -> Module:
998998

999999
def test_aliases(self) -> None:
10001000
def test_from(node: ImportFrom) -> ImportFrom:
1001-
node.names = node.names + [("absolute_import", None)]
1001+
node.names = [*node.names, ("absolute_import", None)]
10021002
return node
10031003

10041004
def test_class(node: ClassDef) -> ClassDef:

tests/test_regrtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def method(self):
267267
"With unicode : {'’'} "
268268
269269
instance = MyClass()
270-
"""
270+
""" # noqa[RUF001]
271271
)
272272

273273
next(node.value.infer()).as_string()

0 commit comments

Comments
 (0)