diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-08-10 20:10:49 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-08-10 20:10:49 +0300 |
commit | 75c86c3059b2c117ea39bdf717296e20500903b1 (patch) | |
tree | bee11bed66786039183d7c5a2edc77e0508dedcb /sphinx/util | |
parent | a7ac325a1bd043707297a1d360091bd38b695dde (diff) | |
parent | e3a8ee9fcf36d48db6b28f2cd73c1bfe90bd9ae3 (diff) |
Merge branch '4.1.x' into 4.x
Diffstat (limited to 'sphinx/util')
-rw-r--r-- | sphinx/util/typing.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index 78feb6492..78b0b5b0a 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -157,7 +157,9 @@ def _restify_py37(cls: Optional[Type]) -> str: args = ', '.join(restify(a) for a in cls.__args__) return ':obj:`~typing.Union`\\ [%s]' % args elif inspect.isgenericalias(cls): - if getattr(cls, '_name', None): + if isinstance(cls.__origin__, typing._SpecialForm): + text = restify(cls.__origin__) # type: ignore + elif getattr(cls, '_name', None): if cls.__module__ == 'typing': text = ':class:`~%s.%s`' % (cls.__module__, cls._name) else: @@ -180,12 +182,8 @@ def _restify_py37(cls: Optional[Type]) -> str: text += r"\ [%s]" % ", ".join(restify(a) for a in cls.__args__) return text - elif hasattr(cls, '_name'): - # SpecialForm - if cls.__module__ == 'typing': - return ':obj:`~%s.%s`' % (cls.__module__, cls._name) - else: - return ':obj:`%s.%s`' % (cls.__module__, cls._name) + elif isinstance(cls, typing._SpecialForm): + return ':obj:`~%s.%s`' % (cls.__module__, cls._name) elif hasattr(cls, '__qualname__'): if cls.__module__ == 'typing': return ':class:`~%s.%s`' % (cls.__module__, cls.__qualname__) @@ -360,7 +358,7 @@ def _stringify_py37(annotation: Any) -> str: if not isinstance(annotation.__args__, (list, tuple)): # broken __args__ found pass - elif qualname == 'Union': + elif qualname in ('Optional', '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]) |