summaryrefslogtreecommitdiff
path: root/sphinx/util/typing.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-10-04 22:41:44 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-10-04 22:41:44 +0900
commit598b85da75bc533004d68b95a5056016dc16df1c (patch)
treee08eae0ea5f098257f01081e4c792bcfeb92eba6 /sphinx/util/typing.py
parent11633f2e53bf01f6844256558444991836815690 (diff)
parent38bb3774643d779b708970f941f2b16d1ab81b89 (diff)
downloadsphinx-git-598b85da75bc533004d68b95a5056016dc16df1c.tar.gz
Merge branch '3.x' into master
Diffstat (limited to 'sphinx/util/typing.py')
-rw-r--r--sphinx/util/typing.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py
index e91939ec2..2987f9ae3 100644
--- a/sphinx/util/typing.py
+++ b/sphinx/util/typing.py
@@ -63,7 +63,11 @@ def is_system_TypeVar(typ: Any) -> bool:
def stringify(annotation: Any) -> str:
"""Stringify type annotation object."""
if isinstance(annotation, str):
- return annotation
+ if annotation.startswith("'") and annotation.endswith("'"):
+ # might be a double Forward-ref'ed type. Go unquoting.
+ return annotation[1:-2]
+ else:
+ return annotation
elif isinstance(annotation, TypeVar): # type: ignore
return annotation.__name__
elif not annotation:
@@ -105,7 +109,10 @@ def _stringify_py37(annotation: Any) -> str:
return repr(annotation)
if getattr(annotation, '__args__', None):
- if qualname == 'Union':
+ if not isinstance(annotation.__args__, (list, tuple)):
+ # broken __args__ found
+ pass
+ elif qualname == 'Union':
if len(annotation.__args__) > 1 and annotation.__args__[-1] is NoneType:
if len(annotation.__args__) > 2:
args = ', '.join(stringify(a) for a in annotation.__args__[:-1])