Merge branch '3.0.x' into 3.x

This commit is contained in:
Takeshi KOMIYA 2020-04-28 01:41:52 +09:00
commit 8c35cfa38a
3 changed files with 29 additions and 7 deletions

19
CHANGES
View File

@ -75,7 +75,7 @@ Bugs fixed
Testing
--------
Release 3.0.3 (in development)
Release 3.0.4 (in development)
==============================
Dependencies
@ -90,6 +90,20 @@ Deprecated
Features added
--------------
Bugs fixed
----------
* #7567: autodoc: parametrized types are shown twice for generic types
Testing
--------
Release 3.0.3 (released Apr 26, 2020)
=====================================
Features added
--------------
* C, parse array declarators with static, qualifiers, and VLA specification.
Bugs fixed
@ -98,9 +112,6 @@ Bugs fixed
* #7516: autodoc: crashes if target object raises an error on accessing
its attributes
Testing
--------
Release 3.0.2 (released Apr 19, 2020)
=====================================

View File

@ -75,8 +75,13 @@ def _stringify_py37(annotation: Any) -> str:
qualname = stringify(annotation.__origin__) # ex. Union
elif hasattr(annotation, '__qualname__'):
qualname = '%s.%s' % (module, annotation.__qualname__)
elif hasattr(annotation, '__origin__'):
# instantiated generic provided by a user
qualname = stringify(annotation.__origin__)
else:
qualname = repr(annotation)
# we weren't able to extract the base type, appending arguments would
# only make them appear twice
return repr(annotation)
if getattr(annotation, '__args__', None):
if qualname == 'Union':
@ -91,7 +96,7 @@ def _stringify_py37(annotation: Any) -> str:
return '%s[[%s], %s]' % (qualname, args, returns)
elif str(annotation).startswith('typing.Annotated'): # for py39+
return stringify(annotation.__args__[0])
elif annotation._special:
elif getattr(annotation, '_special', False):
return qualname
else:
args = ', '.join(stringify(a) for a in annotation.__args__)

View File

@ -10,7 +10,7 @@
import sys
from numbers import Integral
from typing import Any, Dict, List, TypeVar, Union, Callable, Tuple, Optional
from typing import Any, Dict, List, TypeVar, Union, Callable, Tuple, Optional, Generic
import pytest
@ -24,6 +24,11 @@ class MyClass1:
class MyClass2(MyClass1):
__qualname__ = '<MyClass2>'
T = TypeVar('T')
class MyList(List[T]):
pass
def test_stringify():
assert stringify(int) == "int"
@ -42,6 +47,7 @@ def test_stringify_type_hints_containers():
assert stringify(Tuple[str, str, str]) == "Tuple[str, str, str]"
assert stringify(Tuple[str, ...]) == "Tuple[str, ...]"
assert stringify(List[Dict[str, Tuple]]) == "List[Dict[str, Tuple]]"
assert stringify(MyList[Tuple[int, int]]) == "test_util_typing.MyList[Tuple[int, int]]"
@pytest.mark.skipif(sys.version_info < (3, 9), reason='python 3.9+ is required.')