Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 3, 2025
1 parent 878c5fc commit bd99b06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import shutil
import sys
from pathlib import Path
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

import pytest
from sphobjinv import Inventory
Expand Down
45 changes: 21 additions & 24 deletions tests/test_sphinx_autodoc_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@
IO,
Any,
AnyStr,
Callable,
Dict,
Generic,
List,
Mapping,
Match,
NewType,
Optional,
Pattern,
Tuple,
Type,
TypeVar,
Expand Down Expand Up @@ -146,20 +142,20 @@ def __getitem__(self, params): # noqa: ANN001, ANN204
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(Callable, "typing", "Callable", (), id="Callable"),
pytest.param(Callable[..., str], "typing", "Callable", (..., str), id="Callable_returntype"),
pytest.param(Callable[[int, str], str], "typing", "Callable", (int, str, str), id="Callable_all_types"),
pytest.param(collections.abc.Callable, "typing", "Callable", (), id="Callable"),
pytest.param(collections.abc.Callable[..., str], "typing", "Callable", (..., str), id="Callable_returntype"),
pytest.param(collections.abc.Callable[[int, str], str], "typing", "Callable", (int, str, str), id="Callable_all_types"),
pytest.param(
AbcCallable[[int, str], str], # type: ignore[type-arg,misc,valid-type]
"collections.abc",
"Callable",
(int, str, str),
id="collections.abc.Callable_all_types",
),
pytest.param(Pattern, "typing", "Pattern", (), id="Pattern"),
pytest.param(Pattern[str], "typing", "Pattern", (str,), id="Pattern_parametrized"),
pytest.param(Match, "typing", "Match", (), id="Match"),
pytest.param(Match[str], "typing", "Match", (str,), id="Match_parametrized"),
pytest.param(re.Pattern, "typing", "Pattern", (), id="Pattern"),
pytest.param(re.Pattern[str], "typing", "Pattern", (str,), id="Pattern_parametrized"),
pytest.param(re.Match, "typing", "Match", (), id="Match"),
pytest.param(re.Match[str], "typing", "Match", (str,), id="Match_parametrized"),
pytest.param(IO, "typing", "IO", (), id="IO"),
pytest.param(W, "typing", "NewType", (str,), id="W"),
pytest.param(P, "typing", "ParamSpec", (), id="P"),
Expand Down Expand Up @@ -197,26 +193,26 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
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"),
pytest.param(Mapping, ":py:class:`~typing.Mapping`", id="Mapping"),
pytest.param(collections.abc.Mapping, ":py:class:`~typing.Mapping`", id="Mapping"),
pytest.param(
Mapping[T, int], # type: ignore[valid-type]
collections.abc.Mapping[T, int], # type: ignore[valid-type]
r":py:class:`~typing.Mapping`\ \[:py:class:`~typing.TypeVar`\ \(``T``), :py:class:`int`]",
id="Mapping-T-int",
),
pytest.param(
Mapping[str, V_contra], # type: ignore[valid-type]
collections.abc.Mapping[str, V_contra], # type: ignore[valid-type]
r":py:class:`~typing.Mapping`\ \[:py:class:`str`, :py:class:`~typing.TypeVar`\ \("
"``V_contra``, contravariant=True)]",
id="Mapping-T-int-contra",
),
pytest.param(
Mapping[T, U_co], # type: ignore[valid-type]
collections.abc.Mapping[T, U_co], # type: ignore[valid-type]
r":py:class:`~typing.Mapping`\ \[:py:class:`~typing.TypeVar`\ \(``T``), "
r":py:class:`~typing.TypeVar`\ \(``U_co``, covariant=True)]",
id="Mapping-T-int-co",
),
pytest.param(
Mapping[str, bool],
collections.abc.Mapping[str, bool],
r":py:class:`~typing.Mapping`\ \[:py:class:`str`, :py:class:`bool`]",
id="Mapping-str-bool",
),
Expand Down Expand Up @@ -290,29 +286,29 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
r":py:data:`~typing.Union`\ \[:py:class:`str`, :py:class:`bool`, :py:obj:`None`]",
id="Optional-Union-str-bool",
),
pytest.param(Callable, ":py:data:`~typing.Callable`", id="Callable"),
pytest.param(collections.abc.Callable, ":py:data:`~typing.Callable`", id="Callable"),
pytest.param(
Callable[..., int],
collections.abc.Callable[..., int],
r":py:data:`~typing.Callable`\ \[:py:data:`...<Ellipsis>`, :py:class:`int`]",
id="Callable-Ellipsis-int",
),
pytest.param(
Callable[[int], int],
collections.abc.Callable[[int], int],
r":py:data:`~typing.Callable`\ \[\[:py:class:`int`], :py:class:`int`]",
id="Callable-int-int",
),
pytest.param(
Callable[[int, str], bool],
collections.abc.Callable[[int, str], bool],
r":py:data:`~typing.Callable`\ \[\[:py:class:`int`, :py:class:`str`], :py:class:`bool`]",
id="Callable-int-str-bool",
),
pytest.param(
Callable[[int, str], None],
collections.abc.Callable[[int, str], None],
r":py:data:`~typing.Callable`\ \[\[:py:class:`int`, :py:class:`str`], :py:obj:`None`]",
id="Callable-int-str",
),
pytest.param(
Callable[[T], T],
collections.abc.Callable[[T], T],
r":py:data:`~typing.Callable`\ \[\[:py:class:`~typing.TypeVar`\ \(``T``)],"
r" :py:class:`~typing.TypeVar`\ \(``T``)]",
id="Callable-T-T",
Expand All @@ -322,8 +318,8 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
r":py:class:`~collections.abc.Callable`\ \[\[:py:class:`int`, :py:class:`str`], :py:class:`bool`]",
id="AbcCallable-int-str-bool",
),
pytest.param(Pattern, ":py:class:`~typing.Pattern`", id="Pattern"),
pytest.param(Pattern[str], r":py:class:`~typing.Pattern`\ \[:py:class:`str`]", id="Pattern-str"),
pytest.param(re.Pattern, ":py:class:`~typing.Pattern`", id="Pattern"),
pytest.param(re.Pattern[str], r":py:class:`~typing.Pattern`\ \[:py:class:`str`]", id="Pattern-str"),
pytest.param(IO, ":py:class:`~typing.IO`", id="IO"),
pytest.param(IO[str], r":py:class:`~typing.IO`\ \[:py:class:`str`]", id="IO-str"),
pytest.param(Metaclass, f":py:class:`~{__name__}.Metaclass`", id="Metaclass"),
Expand Down Expand Up @@ -384,6 +380,7 @@ def test_parse_annotation(annotation: Any, module: str, class_name: str, args: t
),
]


@pytest.mark.parametrize(("annotation", "expected_result"), _CASES)
def test_format_annotation(inv: Inventory, annotation: Any, expected_result: str) -> None:
conf = create_autospec(Config, _annotation_globals=globals(), always_use_bars_union=False)
Expand Down

0 comments on commit bd99b06

Please sign in to comment.