diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-04-28 01:42:37 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-04-28 01:42:37 +0900 |
commit | aa773cbc88e692df731c78353a1043201bcb9f91 (patch) | |
tree | 2e5fc2c4659d73333a01f2a2c1c00420d98a801f /sphinx/util/typing.py | |
parent | bee44bedb100d325e4e9dad681521819bd774f5f (diff) | |
parent | ba47b7055b03050ed7d7803cb0d1c7a335646ecf (diff) | |
download | sphinx-git-aa773cbc88e692df731c78353a1043201bcb9f91.tar.gz |
Merge branch '3.x'
Diffstat (limited to 'sphinx/util/typing.py')
-rw-r--r-- | sphinx/util/typing.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index c2e683eee..72da10dd1 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -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__) |