Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-09-11 11:19:54 +0300
committerGitHub <noreply@github.com>2021-09-11 11:19:54 +0300
commitc44ee0ebaa8039a4e1014fa02f485c4693414e17 (patch)
treef47ff35f40e68368d5d7c64199bea5de84b300a3 /sphinx/util
parent8416813168baa32449af1e9a2047282d57efc9fa (diff)
parentc5b35efce353a3e1670185704bcd1453b9da3533 (diff)
Merge pull request #9611 from tk0miya/9560_NewType_module
Close #9560: autodoc: Allow to refer NewType with modname in py310+
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/typing.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py
index c0a038420..8912de8cd 100644
--- a/sphinx/util/typing.py
+++ b/sphinx/util/typing.py
@@ -116,7 +116,12 @@ def restify(cls: Optional[Type]) -> str:
elif cls in INVALID_BUILTIN_CLASSES:
return ':class:`%s`' % INVALID_BUILTIN_CLASSES[cls]
elif inspect.isNewType(cls):
- return ':class:`%s`' % cls.__name__
+ if sys.version_info > (3, 10):
+ # newtypes have correct module info since Python 3.10+
+ print(cls, type(cls), dir(cls))
+ return ':class:`%s.%s`' % (cls.__module__, cls.__name__)
+ else:
+ return ':class:`%s`' % cls.__name__
elif UnionType and isinstance(cls, UnionType):
if len(cls.__args__) > 1 and None in cls.__args__:
args = ' | '.join(restify(a) for a in cls.__args__ if a)
@@ -307,8 +312,11 @@ def stringify(annotation: Any) -> str:
else:
return '.'.join([annotation.__module__, annotation.__name__])
elif inspect.isNewType(annotation):
- # Could not get the module where it defined
- return annotation.__name__
+ if sys.version_info > (3, 10):
+ # newtypes have correct module info since Python 3.10+
+ return '%s.%s' % (annotation.__module__, annotation.__name__)
+ else:
+ return annotation.__name__
elif not annotation:
return repr(annotation)
elif annotation is NoneType: