Skip to content

Commit 4fa3651

Browse files
committed
chore: Updates pre-commit hooks to latest version and applies fixes
1 parent 7e18817 commit 4fa3651

26 files changed

Lines changed: 352 additions & 697 deletions

.pre-commit-config.yaml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 24.10.0
3+
rev: 25.12.0
44
hooks:
55
- id: black
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v5.0.0
7+
rev: v6.0.0
88
hooks:
99
- id: check-ast
1010
- id: check-added-large-files
@@ -19,7 +19,7 @@ repos:
1919
- id: mixed-line-ending
2020
- id: trailing-whitespace
2121
- repo: https://github.com/pycqa/flake8
22-
rev: 7.1.1
22+
rev: 7.3.0
2323
hooks:
2424
- id: flake8
2525
additional_dependencies: [
@@ -34,18 +34,24 @@ repos:
3434
'flake8-type-checking==2.9.1',
3535
]
3636
- repo: https://github.com/asottile/pyupgrade
37-
rev: v3.19.0
37+
rev: v3.21.2
3838
hooks:
3939
- id: pyupgrade
4040
args: [ "--py39-plus", '--keep-runtime-typing' ]
4141
- repo: https://github.com/pycqa/isort
42-
rev: 5.13.2
42+
rev: 7.0.0
4343
hooks:
4444
- id: isort
4545
- repo: https://github.com/pre-commit/mirrors-mypy
46-
rev: v1.13.0
46+
rev: v1.19.1
4747
hooks:
4848
- id: mypy
4949
additional_dependencies:
5050
- pytest
5151
- flake8
52+
# NOTE: We want this hook to always run, but exactly once
53+
# instead of for every file. So we exclude all files
54+
exclude: '.*'
55+
always_run: true
56+
pass_filenames: false
57+
args: ['-p', 'flake8_type_checking']

flake8_type_checking/checker.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def visit_Constant(self, node: ast.Constant) -> ast.Constant:
223223
# just needs to be available in global scope anywhere, we handle
224224
# this by special casing `ast.Constant` when we look for used type
225225
# checking symbols
226-
self.uses[node.value].append((node, self.current_scope))
226+
self.uses[node.value].append((node, self.current_scope)) # type: ignore[index]
227227
return node
228228

229229

@@ -287,6 +287,7 @@ def visit_annotation_name(self, node: ast.Name) -> None:
287287

288288
def visit_annotation_string(self, node: ast.Constant) -> None:
289289
"""Add all the names in the string to mapped names."""
290+
assert isinstance(node.value, str)
290291
visitor = StringAnnotationVisitor(self.plugin)
291292
visitor.parse_and_visit_string_annotation(node.value)
292293
self.plugin.soft_uses.update(visitor.names)
@@ -838,6 +839,7 @@ def visit_annotation_name(self, node: ast.Name) -> None:
838839

839840
def visit_annotation_string(self, node: ast.Constant) -> None:
840841
"""Parse and visit nested string annotations."""
842+
assert isinstance(node.value, str)
841843
self.parse_and_visit_string_annotation(node.value)
842844

843845

@@ -902,6 +904,7 @@ def visit_annotation_name(self, node: ast.Name) -> None:
902904

903905
def visit_annotation_string(self, node: ast.Constant) -> None:
904906
"""Register wrapped annotation and invalid binop literals."""
907+
assert isinstance(node.value, str)
905908
setattr(node, ANNOTATION_PROPERTY, True)
906909
# we don't want to register them as both so we don't emit redundant errors
907910
if getattr(node, BINOP_OPERAND_PROPERTY, False):
@@ -962,6 +965,7 @@ def visit_annotation_name(self, node: ast.Name) -> None:
962965

963966
def visit_annotation_string(self, node: ast.Constant) -> None:
964967
"""Collect all the names referenced inside the forward reference."""
968+
assert isinstance(node.value, str)
965969
visitor = StringAnnotationVisitor(self._typing_lookup)
966970
visitor.parse_and_visit_string_annotation(node.value)
967971
self.quoted_names.update(visitor.names)
@@ -1178,7 +1182,7 @@ def are_annotations_deferred(self) -> bool:
11781182
This is the case when either there is a `from __future__ import annotations`
11791183
import present or we're targetting Python 3.14+.
11801184
"""
1181-
return self.py314plus or self.futures_annotation
1185+
return self.py314plus or self.futures_annotation is True
11821186

11831187
def is_typing(self, node: ast.AST, symbol: str) -> bool:
11841188
"""Check if the given node matches the given typing symbol."""

tests/test_attrs.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ def test_attrs_model(imp, dec):
2828
Test `attrs` classes together with a non-`attrs` class that has a class var of the same type.
2929
`attrs` classes are instantiated using different dataclass decorators. The `attrs` module is imported as whole.
3030
"""
31-
example = textwrap.dedent(
32-
f'''
31+
example = textwrap.dedent(f'''
3332
{imp}
3433
from decimal import Decimal
3534
@@ -43,8 +42,7 @@ class Y:
4342
4443
class Z:
4544
x: Decimal
46-
'''
47-
)
45+
''')
4846
assert _get_error(example, error_code_filter='TC001,TC002,TC003') == set()
4947

5048

@@ -65,8 +63,7 @@ def test_complex_attrs_model(imp, dec, expected):
6563
Test `attrs` classes together with a non-`attrs` class tha has a class var of another type.
6664
`attrs` classes are instantiated using different dataclass decorators. The `attrs` module is imported as whole.
6765
"""
68-
example = textwrap.dedent(
69-
f'''
66+
example = textwrap.dedent(f'''
7067
{imp}
7168
from decimals import Decimal
7269
from decimal import Context
@@ -81,8 +78,7 @@ class Y:
8178
8279
class Z:
8380
x: Context
84-
'''
85-
)
81+
''')
8682
assert _get_error(example, error_code_filter='TC001,TC002,TC003') == expected
8783

8884

@@ -103,8 +99,7 @@ def test_complex_attrs_model_direct_import(imp, dec, expected):
10399
Test `attrs` classes together with a non-`attrs` class tha has a class var of another type.
104100
`attrs` classes are instantiated using different dataclass decorators which are imported as submodules.
105101
"""
106-
example = textwrap.dedent(
107-
f'''
102+
example = textwrap.dedent(f'''
108103
{imp}
109104
from decimals import Decimal
110105
from decimal import Context
@@ -119,8 +114,7 @@ class Y:
119114
120115
class Z:
121116
x: Context
122-
'''
123-
)
117+
''')
124118
assert _get_error(example, error_code_filter='TC001,TC002,TC003') == expected
125119

126120

@@ -150,8 +144,7 @@ def test_complex_attrs_model_as_import(imp, dec, expected):
150144
`attrs` classes are instantiated using different dataclass
151145
decorators which are imported as submodules using an alias.
152146
"""
153-
example = textwrap.dedent(
154-
f'''
147+
example = textwrap.dedent(f'''
155148
{imp}
156149
from decimals import Decimal
157150
from decimal import Context
@@ -166,8 +159,7 @@ class Y:
166159
167160
class Z:
168161
x: Context
169-
'''
170-
)
162+
''')
171163
assert _get_error(example, error_code_filter='TC001,TC002,TC003') == expected
172164

173165

@@ -193,8 +185,7 @@ def test_complex_attrs_model_slots_frozen(imp, dec, expected):
193185
Test `attrs` classes together with a non-`attrs` class tha has a class var of another type.
194186
`attrs` classes are instantiated using different dataclass decorators and arguments.
195187
"""
196-
example = textwrap.dedent(
197-
f'''
188+
example = textwrap.dedent(f'''
198189
{imp}
199190
from decimals import Decimal
200191
from decimal import Context
@@ -209,6 +200,5 @@ class Y:
209200
210201
class Z:
211202
x: Context
212-
'''
213-
)
203+
''')
214204
assert _get_error(example, error_code_filter='TC001,TC002,TC003') == expected

0 commit comments

Comments
 (0)