Skip to content

Commit

Permalink
Update Ruff to 0.9.1 (#517)
Browse files Browse the repository at this point in the history
And clean up noqa usage in tests
  • Loading branch information
flying-sheep authored Jan 16, 2025
1 parent aceb328 commit 1fda047
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.30.0
rev: "0.30.0"
hooks:
- id: check-github-workflows
args: ["--verbose"]
Expand All @@ -24,7 +24,7 @@ repos:
hooks:
- id: pyproject-fmt
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.8.5"
rev: "v0.9.1"
hooks:
- id: ruff-format
- id: ruff
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ lint.per-file-ignores."tests/**/*.py" = [
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
"S101", # asserts allowed in tests
"S603", # `subprocess` call: check for execution of untrusted input
"UP006", # we test for old List/Tuple syntax
"UP007", # we test for old Union syntax
"UP045", # we test for old Optional syntax
]
lint.isort = { known-first-party = [
"sphinx_autodoc_typehints",
Expand Down
14 changes: 7 additions & 7 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ class Class:
:param z: baz
"""

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

def a_method(self, x: bool, y: int, z: Optional[str] = None) -> str: # noqa: UP007
def a_method(self, x: bool, y: int, z: Optional[str] = None) -> str:
"""
Method docstring.
Expand Down Expand Up @@ -182,7 +182,7 @@ def __magic_custom_method__(self, x: str) -> str: # noqa: PLW3201
"""

@classmethod
def a_classmethod(cls, x: bool, y: int, z: Optional[str] = None) -> str: # noqa: UP007
def a_classmethod(cls, x: bool, y: int, z: Optional[str] = None) -> str:
"""
Classmethod docstring.
Expand All @@ -192,7 +192,7 @@ def a_classmethod(cls, x: bool, y: int, z: Optional[str] = None) -> str: # noqa
"""

@staticmethod
def a_staticmethod(x: bool, y: int, z: Optional[str] = None) -> str: # noqa: UP007
def a_staticmethod(x: bool, y: int, z: Optional[str] = None) -> str:
"""
Staticmethod docstring.
Expand Down Expand Up @@ -270,7 +270,7 @@ def __init__(self, message: str) -> None:
bytes
""",
)
def function(x: bool, y: int, z_: Optional[str] = None) -> str: # noqa: UP007
def function(x: bool, y: int, z_: Optional[str] = None) -> str:
"""
Function docstring.
Expand Down Expand Up @@ -647,7 +647,7 @@ def func_with_overload(a: str, b: str) -> None: ...
"None"
""",
)
def func_with_overload(a: Union[int, str], b: Union[int, str]) -> None: # noqa: UP007
def func_with_overload(a: Union[int, str], b: Union[int, str]) -> None:
"""
f does the thing. The arguments can either be ints or strings but they must
both have the same type.
Expand Down Expand Up @@ -675,7 +675,7 @@ class mod.TestClassAttributeDocs
class TestClassAttributeDocs:
"""A class"""

code: Optional[CodeType] # noqa: UP007
code: Optional[CodeType]
"""An attribute"""


Expand Down
66 changes: 33 additions & 33 deletions tests/test_sphinx_autodoc_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@

# Mypy does not support recursive type aliases, but
# other type checkers do.
RecList = Union[int, List["RecList"]] # noqa: UP006, UP007
MutualRecA = Union[bool, List["MutualRecB"]] # noqa: UP006, UP007
MutualRecB = Union[str, List["MutualRecA"]] # noqa: UP006, UP007
RecList = Union[int, List["RecList"]]
MutualRecA = Union[bool, List["MutualRecB"]]
MutualRecB = Union[str, List["MutualRecA"]]


class A:
Expand Down Expand Up @@ -119,12 +119,12 @@ def method(self: T) -> T: # type: ignore[empty-body]
pytest.param(types.CoroutineType, "types", "CoroutineType", (), id="CoroutineType"),
pytest.param(Any, "typing", "Any", (), id="Any"),
pytest.param(AnyStr, "typing", "AnyStr", (), id="AnyStr"),
pytest.param(Dict, "typing", "Dict", (), id="Dict"), # noqa: UP006
pytest.param(Dict[str, int], "typing", "Dict", (str, int), id="Dict_parametrized"), # noqa: UP006
pytest.param(Dict[T, int], "typing", "Dict", (T, int), id="Dict_typevar"), # type: ignore[valid-type] # noqa: UP006
pytest.param(Tuple, "typing", "Tuple", (), id="Tuple"), # noqa: UP006
pytest.param(Tuple[str, int], "typing", "Tuple", (str, int), id="Tuple_parametrized"), # noqa: UP006
pytest.param(Union[str, int], "typing", "Union", (str, int), id="Union"), # noqa: UP007
pytest.param(Dict, "typing", "Dict", (), id="Dict"),
pytest.param(Dict[str, int], "typing", "Dict", (str, int), id="Dict_parametrized"),
pytest.param(Dict[T, int], "typing", "Dict", (T, int), id="Dict_typevar"), # type: ignore[valid-type]
pytest.param(Tuple, "typing", "Tuple", (), id="Tuple"),
pytest.param(Tuple[str, int], "typing", "Tuple", (str, int), id="Tuple_parametrized"),
pytest.param(Union[str, int], "typing", "Union", (str, int), id="Union"),
pytest.param(Callable, "collections.abc", "Callable", (), id="Callable"),
pytest.param(Callable[..., str], "collections.abc", "Callable", (..., str), id="Callable_returntype"),
pytest.param(
Expand Down Expand Up @@ -177,8 +177,8 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
pytest.param(type(None), ":py:obj:`None`", id="type None"),
pytest.param(type, ":py:class:`type`", id="type"),
pytest.param(Callable, ":py:class:`~collections.abc.Callable`", id="abc-Callable"),
pytest.param(Type, ":py:class:`~typing.Type`", id="typing-Type"), # noqa: UP006
pytest.param(Type[A], rf":py:class:`~typing.Type`\ \[:py:class:`~{__name__}.A`]", id="typing-A"), # noqa: UP006
pytest.param(Type, ":py:class:`~typing.Type`", id="typing-Type"),
pytest.param(Type[A], rf":py:class:`~typing.Type`\ \[:py:class:`~{__name__}.A`]", id="typing-A"),
pytest.param(Any, ":py:data:`~typing.Any`", id="Any"),
pytest.param(AnyStr, ":py:data:`~typing.AnyStr`", id="AnyStr"),
pytest.param(Generic[T], r":py:class:`~typing.Generic`\ \[:py:class:`~typing.TypeVar`\ \(``T``)]", id="Generic"),
Expand All @@ -205,73 +205,73 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
r":py:class:`~collections.abc.Mapping`\ \[:py:class:`str`, :py:class:`bool`]",
id="Mapping-str-bool",
),
pytest.param(Dict, ":py:class:`~typing.Dict`", id="Dict"), # noqa: UP006
pytest.param(Dict, ":py:class:`~typing.Dict`", id="Dict"),
pytest.param(
Dict[T, int], # type: ignore[valid-type] # noqa: UP006
Dict[T, int], # type: ignore[valid-type]
r":py:class:`~typing.Dict`\ \[:py:class:`~typing.TypeVar`\ \(``T``), :py:class:`int`]",
id="Dict-T-int",
),
pytest.param(
Dict[str, V_contra], # type: ignore[valid-type] # noqa: UP006
Dict[str, V_contra], # type: ignore[valid-type]
r":py:class:`~typing.Dict`\ \[:py:class:`str`, :py:class:`~typing.TypeVar`\ \(``V_contra``, "
r"contravariant=True)]",
id="Dict-T-int-contra",
),
pytest.param(
Dict[T, U_co], # type: ignore[valid-type] # noqa: UP006
Dict[T, U_co], # type: ignore[valid-type]
r":py:class:`~typing.Dict`\ \[:py:class:`~typing.TypeVar`\ \(``T``),"
r" :py:class:`~typing.TypeVar`\ \(``U_co``, covariant=True)]",
id="Dict-T-int-co",
),
pytest.param(
Dict[str, bool], # noqa: UP006
Dict[str, bool],
r":py:class:`~typing.Dict`\ \[:py:class:`str`, :py:class:`bool`]",
id="Dict-str-bool", # noqa: RUF100, UP006
id="Dict-str-bool",
),
pytest.param(Tuple, ":py:data:`~typing.Tuple`", id="Tuple"), # noqa: UP006
pytest.param(Tuple, ":py:data:`~typing.Tuple`", id="Tuple"),
pytest.param(
Tuple[str, bool], # noqa: UP006
Tuple[str, bool],
r":py:data:`~typing.Tuple`\ \[:py:class:`str`, :py:class:`bool`]",
id="Tuple-str-bool", # noqa: RUF100, UP006
id="Tuple-str-bool",
),
pytest.param(
Tuple[int, int, int], # noqa: UP006
Tuple[int, int, int],
r":py:data:`~typing.Tuple`\ \[:py:class:`int`, :py:class:`int`, :py:class:`int`]",
id="Tuple-int-int-int",
),
pytest.param(
Tuple[str, ...], # noqa: UP006
Tuple[str, ...],
r":py:data:`~typing.Tuple`\ \[:py:class:`str`, :py:data:`...<Ellipsis>`]",
id="Tuple-str-Ellipsis",
),
pytest.param(Union, ":py:data:`~typing.Union`", id="Union"),
pytest.param(
Union[str, bool], # noqa: UP007
Union[str, bool],
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`]",
id="Union-str-bool",
),
pytest.param(
Union[str, bool, None], # noqa: UP007
Union[str, bool, None],
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`, :py:obj:`None`]",
id="Union-str-bool-None",
),
pytest.param(
Union[str, Any], # noqa: UP007
Union[str, Any],
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:data:`~typing.Any`]",
id="Union-str-Any",
),
pytest.param(
Optional[str], # noqa: UP007
Optional[str],
r":py:data:`~typing.Optional`\ \[:py:class:`str`]",
id="Optional-str",
),
pytest.param(
Union[str, None], # noqa: UP007
Union[str, None],
r":py:data:`~typing.Optional`\ \[:py:class:`str`]",
id="Optional-str-None",
),
pytest.param(
Optional[str | bool], # noqa: UP007
Optional[str | bool],
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`, :py:obj:`None`]",
id="Optional-Union-str-bool",
),
Expand Down Expand Up @@ -345,17 +345,17 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
pytest.param(P_bound, r":py:class:`~typing.ParamSpec`\ \(``P_bound``, bound= :py:class:`str`)", id="P-bound"),
# ## These test for correct internal tuple rendering, even if not all are valid Tuple types
# Zero-length tuple remains
pytest.param(Tuple[()], ":py:data:`~typing.Tuple`", id="Tuple-p"), # noqa: UP006
pytest.param(Tuple[()], ":py:data:`~typing.Tuple`", id="Tuple-p"),
# Internal single tuple with simple types is flattened in the output
pytest.param(Tuple[int,], r":py:data:`~typing.Tuple`\ \[:py:class:`int`]", id="Tuple-p-int"), # noqa: UP006
pytest.param(Tuple[int,], r":py:data:`~typing.Tuple`\ \[:py:class:`int`]", id="Tuple-p-int"),
pytest.param(
Tuple[int, int], # noqa: UP006
Tuple[int, int],
r":py:data:`~typing.Tuple`\ \[:py:class:`int`, :py:class:`int`]",
id="Tuple-p-int-int", # noqa: RUF100, UP006
id="Tuple-p-int-int",
),
# Ellipsis in single tuple also gets flattened
pytest.param(
Tuple[int, ...], # noqa: UP006
Tuple[int, ...],
r":py:data:`~typing.Tuple`\ \[:py:class:`int`, :py:data:`...<Ellipsis>`]",
id="Tuple-p-Ellipsis",
),
Expand Down

0 comments on commit 1fda047

Please sign in to comment.