Skip to content

Commit

Permalink
Respond to feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Gobot1234 committed Jul 18, 2021
1 parent 31e07c7 commit 451811c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sphinx/util/typing.py
Expand Up @@ -312,7 +312,8 @@ def stringify(annotation: Any) -> str:
hasattr(annotation, '__qualname__')):
if hasattr(annotation, '__args__'): # PEP 585 generic
return repr(annotation)
return annotation.__qualname__
else:
return annotation.__qualname__
elif annotation is Ellipsis:
return '...'

Expand Down
12 changes: 12 additions & 0 deletions tests/test_util_typing.py
Expand Up @@ -175,6 +175,18 @@ def test_stringify_type_hints_containers():
assert stringify(Generator[None, None, None]) == "Generator[None, None, None]"


@pytest.mark.skipif(sys.version_info < (3, 9), reason='python 3.9+ is required.')
def test_stringify_type_hints_pep_585():
assert stringify(list[int]) == "list[int]"
assert stringify(list[str]) == "list[str]"
assert stringify(dict[str, float]) == "dict[str, float]"
assert stringify(tuple[str, str, str]) == "tuple[str, str, str]"
assert stringify(tuple[str, ...]) == "tuple[str, ...]"
assert stringify(tuple[()]) == "tuple[()]"
assert stringify(list[dict[str, tuple]]) == "list[dict[str, tuple]]"
assert stringify(type[int]) == "type[int]"


@pytest.mark.skipif(sys.version_info < (3, 9), reason='python 3.9+ is required.')
def test_stringify_Annotated():
from typing import Annotated # type: ignore
Expand Down

0 comments on commit 451811c

Please sign in to comment.