Skip to content

Commit 1fda047

Browse files
authored
Update Ruff to 0.9.1 (#517)
And clean up noqa usage in tests
1 parent aceb328 commit 1fda047

File tree

4 files changed

+45
-42
lines changed

4 files changed

+45
-42
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repos:
55
- id: end-of-file-fixer
66
- id: trailing-whitespace
77
- repo: https://github.com/python-jsonschema/check-jsonschema
8-
rev: 0.30.0
8+
rev: "0.30.0"
99
hooks:
1010
- id: check-github-workflows
1111
args: ["--verbose"]
@@ -24,7 +24,7 @@ repos:
2424
hooks:
2525
- id: pyproject-fmt
2626
- repo: https://github.com/astral-sh/ruff-pre-commit
27-
rev: "v0.8.5"
27+
rev: "v0.9.1"
2828
hooks:
2929
- id: ruff-format
3030
- id: ruff

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ lint.per-file-ignores."tests/**/*.py" = [
9393
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
9494
"S101", # asserts allowed in tests
9595
"S603", # `subprocess` call: check for execution of untrusted input
96+
"UP006", # we test for old List/Tuple syntax
97+
"UP007", # we test for old Union syntax
98+
"UP045", # we test for old Optional syntax
9699
]
97100
lint.isort = { known-first-party = [
98101
"sphinx_autodoc_typehints",

tests/test_integration.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ class Class:
148148
:param z: baz
149149
"""
150150

151-
def __init__(self, x: bool, y: int, z: Optional[str] = None) -> None: # noqa: UP007
151+
def __init__(self, x: bool, y: int, z: Optional[str] = None) -> None:
152152
pass
153153

154-
def a_method(self, x: bool, y: int, z: Optional[str] = None) -> str: # noqa: UP007
154+
def a_method(self, x: bool, y: int, z: Optional[str] = None) -> str:
155155
"""
156156
Method docstring.
157157
@@ -182,7 +182,7 @@ def __magic_custom_method__(self, x: str) -> str: # noqa: PLW3201
182182
"""
183183

184184
@classmethod
185-
def a_classmethod(cls, x: bool, y: int, z: Optional[str] = None) -> str: # noqa: UP007
185+
def a_classmethod(cls, x: bool, y: int, z: Optional[str] = None) -> str:
186186
"""
187187
Classmethod docstring.
188188
@@ -192,7 +192,7 @@ def a_classmethod(cls, x: bool, y: int, z: Optional[str] = None) -> str: # noqa
192192
"""
193193

194194
@staticmethod
195-
def a_staticmethod(x: bool, y: int, z: Optional[str] = None) -> str: # noqa: UP007
195+
def a_staticmethod(x: bool, y: int, z: Optional[str] = None) -> str:
196196
"""
197197
Staticmethod docstring.
198198
@@ -270,7 +270,7 @@ def __init__(self, message: str) -> None:
270270
bytes
271271
""",
272272
)
273-
def function(x: bool, y: int, z_: Optional[str] = None) -> str: # noqa: UP007
273+
def function(x: bool, y: int, z_: Optional[str] = None) -> str:
274274
"""
275275
Function docstring.
276276
@@ -647,7 +647,7 @@ def func_with_overload(a: str, b: str) -> None: ...
647647
"None"
648648
""",
649649
)
650-
def func_with_overload(a: Union[int, str], b: Union[int, str]) -> None: # noqa: UP007
650+
def func_with_overload(a: Union[int, str], b: Union[int, str]) -> None:
651651
"""
652652
f does the thing. The arguments can either be ints or strings but they must
653653
both have the same type.
@@ -675,7 +675,7 @@ class mod.TestClassAttributeDocs
675675
class TestClassAttributeDocs:
676676
"""A class"""
677677

678-
code: Optional[CodeType] # noqa: UP007
678+
code: Optional[CodeType]
679679
"""An attribute"""
680680

681681

tests/test_sphinx_autodoc_typehints.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363

6464
# Mypy does not support recursive type aliases, but
6565
# other type checkers do.
66-
RecList = Union[int, List["RecList"]] # noqa: UP006, UP007
67-
MutualRecA = Union[bool, List["MutualRecB"]] # noqa: UP006, UP007
68-
MutualRecB = Union[str, List["MutualRecA"]] # noqa: UP006, UP007
66+
RecList = Union[int, List["RecList"]]
67+
MutualRecA = Union[bool, List["MutualRecB"]]
68+
MutualRecB = Union[str, List["MutualRecA"]]
6969

7070

7171
class A:
@@ -119,12 +119,12 @@ def method(self: T) -> T: # type: ignore[empty-body]
119119
pytest.param(types.CoroutineType, "types", "CoroutineType", (), id="CoroutineType"),
120120
pytest.param(Any, "typing", "Any", (), id="Any"),
121121
pytest.param(AnyStr, "typing", "AnyStr", (), id="AnyStr"),
122-
pytest.param(Dict, "typing", "Dict", (), id="Dict"), # noqa: UP006
123-
pytest.param(Dict[str, int], "typing", "Dict", (str, int), id="Dict_parametrized"), # noqa: UP006
124-
pytest.param(Dict[T, int], "typing", "Dict", (T, int), id="Dict_typevar"), # type: ignore[valid-type] # noqa: UP006
125-
pytest.param(Tuple, "typing", "Tuple", (), id="Tuple"), # noqa: UP006
126-
pytest.param(Tuple[str, int], "typing", "Tuple", (str, int), id="Tuple_parametrized"), # noqa: UP006
127-
pytest.param(Union[str, int], "typing", "Union", (str, int), id="Union"), # noqa: UP007
122+
pytest.param(Dict, "typing", "Dict", (), id="Dict"),
123+
pytest.param(Dict[str, int], "typing", "Dict", (str, int), id="Dict_parametrized"),
124+
pytest.param(Dict[T, int], "typing", "Dict", (T, int), id="Dict_typevar"), # type: ignore[valid-type]
125+
pytest.param(Tuple, "typing", "Tuple", (), id="Tuple"),
126+
pytest.param(Tuple[str, int], "typing", "Tuple", (str, int), id="Tuple_parametrized"),
127+
pytest.param(Union[str, int], "typing", "Union", (str, int), id="Union"),
128128
pytest.param(Callable, "collections.abc", "Callable", (), id="Callable"),
129129
pytest.param(Callable[..., str], "collections.abc", "Callable", (..., str), id="Callable_returntype"),
130130
pytest.param(
@@ -177,8 +177,8 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
177177
pytest.param(type(None), ":py:obj:`None`", id="type None"),
178178
pytest.param(type, ":py:class:`type`", id="type"),
179179
pytest.param(Callable, ":py:class:`~collections.abc.Callable`", id="abc-Callable"),
180-
pytest.param(Type, ":py:class:`~typing.Type`", id="typing-Type"), # noqa: UP006
181-
pytest.param(Type[A], rf":py:class:`~typing.Type`\ \[:py:class:`~{__name__}.A`]", id="typing-A"), # noqa: UP006
180+
pytest.param(Type, ":py:class:`~typing.Type`", id="typing-Type"),
181+
pytest.param(Type[A], rf":py:class:`~typing.Type`\ \[:py:class:`~{__name__}.A`]", id="typing-A"),
182182
pytest.param(Any, ":py:data:`~typing.Any`", id="Any"),
183183
pytest.param(AnyStr, ":py:data:`~typing.AnyStr`", id="AnyStr"),
184184
pytest.param(Generic[T], r":py:class:`~typing.Generic`\ \[:py:class:`~typing.TypeVar`\ \(``T``)]", id="Generic"),
@@ -205,73 +205,73 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
205205
r":py:class:`~collections.abc.Mapping`\ \[:py:class:`str`, :py:class:`bool`]",
206206
id="Mapping-str-bool",
207207
),
208-
pytest.param(Dict, ":py:class:`~typing.Dict`", id="Dict"), # noqa: UP006
208+
pytest.param(Dict, ":py:class:`~typing.Dict`", id="Dict"),
209209
pytest.param(
210-
Dict[T, int], # type: ignore[valid-type] # noqa: UP006
210+
Dict[T, int], # type: ignore[valid-type]
211211
r":py:class:`~typing.Dict`\ \[:py:class:`~typing.TypeVar`\ \(``T``), :py:class:`int`]",
212212
id="Dict-T-int",
213213
),
214214
pytest.param(
215-
Dict[str, V_contra], # type: ignore[valid-type] # noqa: UP006
215+
Dict[str, V_contra], # type: ignore[valid-type]
216216
r":py:class:`~typing.Dict`\ \[:py:class:`str`, :py:class:`~typing.TypeVar`\ \(``V_contra``, "
217217
r"contravariant=True)]",
218218
id="Dict-T-int-contra",
219219
),
220220
pytest.param(
221-
Dict[T, U_co], # type: ignore[valid-type] # noqa: UP006
221+
Dict[T, U_co], # type: ignore[valid-type]
222222
r":py:class:`~typing.Dict`\ \[:py:class:`~typing.TypeVar`\ \(``T``),"
223223
r" :py:class:`~typing.TypeVar`\ \(``U_co``, covariant=True)]",
224224
id="Dict-T-int-co",
225225
),
226226
pytest.param(
227-
Dict[str, bool], # noqa: UP006
227+
Dict[str, bool],
228228
r":py:class:`~typing.Dict`\ \[:py:class:`str`, :py:class:`bool`]",
229-
id="Dict-str-bool", # noqa: RUF100, UP006
229+
id="Dict-str-bool",
230230
),
231-
pytest.param(Tuple, ":py:data:`~typing.Tuple`", id="Tuple"), # noqa: UP006
231+
pytest.param(Tuple, ":py:data:`~typing.Tuple`", id="Tuple"),
232232
pytest.param(
233-
Tuple[str, bool], # noqa: UP006
233+
Tuple[str, bool],
234234
r":py:data:`~typing.Tuple`\ \[:py:class:`str`, :py:class:`bool`]",
235-
id="Tuple-str-bool", # noqa: RUF100, UP006
235+
id="Tuple-str-bool",
236236
),
237237
pytest.param(
238-
Tuple[int, int, int], # noqa: UP006
238+
Tuple[int, int, int],
239239
r":py:data:`~typing.Tuple`\ \[:py:class:`int`, :py:class:`int`, :py:class:`int`]",
240240
id="Tuple-int-int-int",
241241
),
242242
pytest.param(
243-
Tuple[str, ...], # noqa: UP006
243+
Tuple[str, ...],
244244
r":py:data:`~typing.Tuple`\ \[:py:class:`str`, :py:data:`...<Ellipsis>`]",
245245
id="Tuple-str-Ellipsis",
246246
),
247247
pytest.param(Union, ":py:data:`~typing.Union`", id="Union"),
248248
pytest.param(
249-
Union[str, bool], # noqa: UP007
249+
Union[str, bool],
250250
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`]",
251251
id="Union-str-bool",
252252
),
253253
pytest.param(
254-
Union[str, bool, None], # noqa: UP007
254+
Union[str, bool, None],
255255
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`, :py:obj:`None`]",
256256
id="Union-str-bool-None",
257257
),
258258
pytest.param(
259-
Union[str, Any], # noqa: UP007
259+
Union[str, Any],
260260
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:data:`~typing.Any`]",
261261
id="Union-str-Any",
262262
),
263263
pytest.param(
264-
Optional[str], # noqa: UP007
264+
Optional[str],
265265
r":py:data:`~typing.Optional`\ \[:py:class:`str`]",
266266
id="Optional-str",
267267
),
268268
pytest.param(
269-
Union[str, None], # noqa: UP007
269+
Union[str, None],
270270
r":py:data:`~typing.Optional`\ \[:py:class:`str`]",
271271
id="Optional-str-None",
272272
),
273273
pytest.param(
274-
Optional[str | bool], # noqa: UP007
274+
Optional[str | bool],
275275
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`, :py:obj:`None`]",
276276
id="Optional-Union-str-bool",
277277
),
@@ -345,17 +345,17 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
345345
pytest.param(P_bound, r":py:class:`~typing.ParamSpec`\ \(``P_bound``, bound= :py:class:`str`)", id="P-bound"),
346346
# ## These test for correct internal tuple rendering, even if not all are valid Tuple types
347347
# Zero-length tuple remains
348-
pytest.param(Tuple[()], ":py:data:`~typing.Tuple`", id="Tuple-p"), # noqa: UP006
348+
pytest.param(Tuple[()], ":py:data:`~typing.Tuple`", id="Tuple-p"),
349349
# Internal single tuple with simple types is flattened in the output
350-
pytest.param(Tuple[int,], r":py:data:`~typing.Tuple`\ \[:py:class:`int`]", id="Tuple-p-int"), # noqa: UP006
350+
pytest.param(Tuple[int,], r":py:data:`~typing.Tuple`\ \[:py:class:`int`]", id="Tuple-p-int"),
351351
pytest.param(
352-
Tuple[int, int], # noqa: UP006
352+
Tuple[int, int],
353353
r":py:data:`~typing.Tuple`\ \[:py:class:`int`, :py:class:`int`]",
354-
id="Tuple-p-int-int", # noqa: RUF100, UP006
354+
id="Tuple-p-int-int",
355355
),
356356
# Ellipsis in single tuple also gets flattened
357357
pytest.param(
358-
Tuple[int, ...], # noqa: UP006
358+
Tuple[int, ...],
359359
r":py:data:`~typing.Tuple`\ \[:py:class:`int`, :py:data:`...<Ellipsis>`]",
360360
id="Tuple-p-Ellipsis",
361361
),

0 commit comments

Comments
 (0)