Respond to feedback

This commit is contained in:
James
2021-07-18 10:55:38 +01:00
parent 31e07c75dd
commit 451811c40c
2 changed files with 14 additions and 1 deletions

View File

@@ -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 '...'

View File

@@ -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