36 lines
1.6 KiB
Diff
36 lines
1.6 KiB
Diff
From 648af37d864b5d76bbe833785d664e40d56d9768 Mon Sep 17 00:00:00 2001
|
|
From: Takeshi KOMIYA <i.tkomiya@gmail.com>
|
|
Date: Wed, 11 Aug 2021 01:36:46 +0900
|
|
Subject: [PATCH] Fix #9537: autodoc: Some typing.* objects are broken
|
|
|
|
At the HEAD of 3.10, the implementation of `typing._GenericAlias` has
|
|
been changed to have correct _name and __name__.
|
|
---
|
|
sphinx/util/typing.py | 6 ++++--
|
|
2 files changed, 6 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py
|
|
index f856950bf2..df5277ae7b 100644
|
|
--- a/sphinx/util/typing.py
|
|
+++ b/sphinx/util/typing.py
|
|
@@ -148,7 +148,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:
|
|
@@ -344,7 +346,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])
|