diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-09-12 16:56:34 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-09-12 16:56:34 +0900 |
commit | 3d8fbd992cedf1784b106cf43ecbc452953ebe17 (patch) | |
tree | 4ec09892ce7a82728a3b8c857b34cb9920854f37 /sphinx/util/typing.py | |
parent | b8b804142903d019b4e222cb85463190cf1978ac (diff) | |
parent | ba2439a105e5a68a44dd3f839e86332889cce451 (diff) | |
download | sphinx-git-3d8fbd992cedf1784b106cf43ecbc452953ebe17.tar.gz |
Merge branch '4.x'
Diffstat (limited to 'sphinx/util/typing.py')
-rw-r--r-- | sphinx/util/typing.py | 14 |
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: |