Skip to content

Commit 15e0bd2

Browse files
[pre-commit] Cherry-pick the tools from the main branch
1 parent 9f4c8fe commit 15e0bd2

File tree

12 files changed

+130
-134
lines changed

12 files changed

+130
-134
lines changed

.pre-commit-config.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ ci:
33

44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.6.0
6+
rev: v5.0.0
77
hooks:
88
- id: trailing-whitespace
99
exclude: .github/|tests/testdata
1010
- id: end-of-file-fixer
1111
exclude: tests/testdata
1212
- repo: https://github.com/astral-sh/ruff-pre-commit
13-
rev: "v0.5.5"
13+
rev: "v0.11.4"
1414
hooks:
1515
- id: ruff
1616
exclude: tests/testdata
@@ -23,7 +23,7 @@ repos:
2323
exclude: tests/testdata|setup.py
2424
types: [python]
2525
- repo: https://github.com/asottile/pyupgrade
26-
rev: v3.17.0
26+
rev: v3.19.1
2727
hooks:
2828
- id: pyupgrade
2929
exclude: tests/testdata
@@ -34,7 +34,7 @@ repos:
3434
- id: black-disable-checker
3535
exclude: tests/test_nodes_lineno.py
3636
- repo: https://github.com/psf/black
37-
rev: 24.4.2
37+
rev: 25.1.0
3838
hooks:
3939
- id: black
4040
args: [--safe, --quiet]
@@ -55,7 +55,7 @@ repos:
5555
]
5656
exclude: tests/testdata|conf.py
5757
- repo: https://github.com/pre-commit/mirrors-mypy
58-
rev: v1.11.0
58+
rev: v1.15.0
5959
hooks:
6060
- id: mypy
6161
name: mypy
@@ -66,8 +66,12 @@ repos:
6666
require_serial: true
6767
additional_dependencies: ["types-typed-ast"]
6868
exclude: tests/testdata| # exclude everything, we're not ready
69-
- repo: https://github.com/pre-commit/mirrors-prettier
70-
rev: v4.0.0-alpha.8
69+
- repo: https://github.com/rbubley/mirrors-prettier
70+
rev: v3.5.3
7171
hooks:
7272
- id: prettier
7373
args: [--prose-wrap=always, --print-width=88]
74+
- repo: https://github.com/tox-dev/pyproject-fmt
75+
rev: "v2.5.1"
76+
hooks:
77+
- id: pyproject-fmt

astroid/brain/brain_typing.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,16 @@ def _looks_like_special_alias(node: Call) -> bool:
357357
PY39: Callable = _CallableType(collections.abc.Callable, 2)
358358
"""
359359
return isinstance(node.func, Name) and (
360-
node.func.name == "_TupleType"
361-
and isinstance(node.args[0], Name)
362-
and node.args[0].name == "tuple"
363-
or node.func.name == "_CallableType"
364-
and isinstance(node.args[0], Attribute)
365-
and node.args[0].as_string() == "collections.abc.Callable"
360+
(
361+
node.func.name == "_TupleType"
362+
and isinstance(node.args[0], Name)
363+
and node.args[0].name == "tuple"
364+
)
365+
or (
366+
node.func.name == "_CallableType"
367+
and isinstance(node.args[0], Attribute)
368+
and node.args[0].as_string() == "collections.abc.Callable"
369+
)
366370
)
367371

368372

@@ -400,10 +404,8 @@ def infer_special_alias(
400404

401405
def _looks_like_typing_cast(node: Call) -> bool:
402406
return isinstance(node, Call) and (
403-
isinstance(node.func, Name)
404-
and node.func.name == "cast"
405-
or isinstance(node.func, Attribute)
406-
and node.func.attrname == "cast"
407+
(isinstance(node.func, Name) and node.func.name == "cast")
408+
or (isinstance(node.func, Attribute) and node.func.attrname == "cast")
407409
)
408410

409411

astroid/context.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ class InferenceContext:
3636
"""
3737

3838
__slots__ = (
39-
"path",
40-
"lookupname",
41-
"callcontext",
39+
"_nodes_inferred",
4240
"boundnode",
43-
"extra_context",
41+
"callcontext",
4442
"constraints",
45-
"_nodes_inferred",
43+
"extra_context",
44+
"lookupname",
45+
"path",
4646
)
4747

4848
max_inferred = 100
@@ -163,7 +163,7 @@ def __str__(self) -> str:
163163
class CallContext:
164164
"""Holds information for a call site."""
165165

166-
__slots__ = ("args", "keywords", "callee")
166+
__slots__ = ("args", "callee", "keywords")
167167

168168
def __init__(
169169
self,

astroid/decorators.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def wrapped(
6060

6161

6262
def yes_if_nothing_inferred(
63-
func: Callable[_P, Generator[InferenceResult]]
63+
func: Callable[_P, Generator[InferenceResult]],
6464
) -> Callable[_P, Generator[InferenceResult]]:
6565
def inner(*args: _P.args, **kwargs: _P.kwargs) -> Generator[InferenceResult]:
6666
generator = func(*args, **kwargs)
@@ -146,11 +146,13 @@ def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _R:
146146
# - len(args) needs to be long enough, if too short
147147
# arg can't be in args either
148148
# - args[index] should not be None
149-
or arg not in kwargs
150-
and (
151-
index == -1
152-
or len(args) <= index
153-
or (len(args) > index and args[index] is None)
149+
or (
150+
arg not in kwargs
151+
and (
152+
index == -1
153+
or len(args) <= index
154+
or (len(args) > index and args[index] is None)
155+
)
154156
)
155157
):
156158
warnings.warn(

astroid/helpers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,8 @@ def object_len(node, context: InferenceContext | None = None):
304304
and result_of_len.pytype() == "builtins.int"
305305
):
306306
return result_of_len.value
307-
if (
308-
result_of_len is None
309-
or isinstance(result_of_len, bases.Instance)
307+
if result_of_len is None or (
308+
isinstance(result_of_len, bases.Instance)
310309
and result_of_len.is_subtype_of("builtins.int")
311310
):
312311
# Fake a result as we don't know the arguments of the instance call.

astroid/nodes/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@
201201
)
202202

203203
__all__ = (
204+
"CONST_CLS",
204205
"AnnAssign",
205-
"are_exclusive",
206206
"Arguments",
207207
"Assert",
208208
"Assign",
@@ -218,20 +218,17 @@
218218
"BinOp",
219219
"BoolOp",
220220
"Break",
221-
"builtin_lookup",
222221
"Call",
223222
"ClassDef",
224-
"CONST_CLS",
225223
"Compare",
226224
"Comprehension",
227225
"ComprehensionScope",
228226
"Const",
229-
"const_factory",
230227
"Continue",
231228
"Decorators",
232229
"DelAttr",
233-
"Delete",
234230
"DelName",
231+
"Delete",
235232
"Dict",
236233
"DictComp",
237234
"DictUnpack",
@@ -242,9 +239,7 @@
242239
"For",
243240
"FormattedValue",
244241
"FunctionDef",
245-
"function_to_method",
246242
"GeneratorExp",
247-
"get_wrapping_class",
248243
"Global",
249244
"If",
250245
"IfExp",
@@ -289,9 +284,14 @@
289284
"TypeVarTuple",
290285
"UnaryOp",
291286
"Unknown",
292-
"unpack_infer",
293287
"While",
294288
"With",
295289
"Yield",
296290
"YieldFrom",
291+
"are_exclusive",
292+
"builtin_lookup",
293+
"const_factory",
294+
"function_to_method",
295+
"get_wrapping_class",
296+
"unpack_infer",
297297
)

astroid/nodes/_base_nodes.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,11 @@ def _get_binop_flow(
608608
and op == "|"
609609
and (
610610
isinstance(left, (bases.UnionType, nodes.ClassDef))
611-
or isinstance(left, nodes.Const)
612-
and left.value is None
611+
or (isinstance(left, nodes.Const) and left.value is None)
613612
)
614613
and (
615614
isinstance(right, (bases.UnionType, nodes.ClassDef))
616-
or isinstance(right, nodes.Const)
617-
and right.value is None
615+
or (isinstance(right, nodes.Const) and right.value is None)
618616
)
619617
):
620618
methods.extend([partial(OperatorNode._bin_op_or_union_type, left, right)])

astroid/nodes/as_string.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ def visit_while(self, node) -> str:
566566
def visit_with(self, node) -> str: # 'with' without 'as' is possible
567567
"""return an astroid.With node as string"""
568568
items = ", ".join(
569-
f"{expr.accept(self)}" + (v and f" as {v.accept(self)}" or "")
569+
f"{expr.accept(self)}" + ((v and f" as {v.accept(self)}") or "")
570570
for expr, v in node.items
571571
)
572572
return f"with {items}:\n{self._stmt_list(node.body)}"

astroid/nodes/scoped_nodes/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"LocalsDictNodeNG",
3939
"Module",
4040
"SetComp",
41+
"_is_metaclass",
4142
"builtin_lookup",
4243
"function_to_method",
4344
"get_wrapping_class",
44-
"_is_metaclass",
4545
)

astroid/nodes/scoped_nodes/scoped_nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@ def scope_lookup(
21832183
)
21842184
if (
21852185
any(
2186-
node == base or base.parent_of(node) and not self.type_params
2186+
node == base or (base.parent_of(node) and not self.type_params)
21872187
for base in self.bases
21882188
)
21892189
or lookup_upper_frame

0 commit comments

Comments
 (0)