Skip to content

Commit 451811c

Browse files
committed
Respond to feedback
1 parent 31e07c7 commit 451811c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

sphinx/util/typing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ def stringify(annotation: Any) -> str:
312312
hasattr(annotation, '__qualname__')):
313313
if hasattr(annotation, '__args__'): # PEP 585 generic
314314
return repr(annotation)
315-
return annotation.__qualname__
315+
else:
316+
return annotation.__qualname__
316317
elif annotation is Ellipsis:
317318
return '...'
318319

tests/test_util_typing.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ def test_stringify_type_hints_containers():
175175
assert stringify(Generator[None, None, None]) == "Generator[None, None, None]"
176176

177177

178+
@pytest.mark.skipif(sys.version_info < (3, 9), reason='python 3.9+ is required.')
179+
def test_stringify_type_hints_pep_585():
180+
assert stringify(list[int]) == "list[int]"
181+
assert stringify(list[str]) == "list[str]"
182+
assert stringify(dict[str, float]) == "dict[str, float]"
183+
assert stringify(tuple[str, str, str]) == "tuple[str, str, str]"
184+
assert stringify(tuple[str, ...]) == "tuple[str, ...]"
185+
assert stringify(tuple[()]) == "tuple[()]"
186+
assert stringify(list[dict[str, tuple]]) == "list[dict[str, tuple]]"
187+
assert stringify(type[int]) == "type[int]"
188+
189+
178190
@pytest.mark.skipif(sys.version_info < (3, 9), reason='python 3.9+ is required.')
179191
def test_stringify_Annotated():
180192
from typing import Annotated # type: ignore

0 commit comments

Comments
 (0)