diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-11-15 07:58:12 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-02-28 09:58:06 +0300 |
commit | 7d3cc382fa2ab875ea168ee40ce34562a387bb40 (patch) | |
tree | 4aacb2a5d06b37893fd1bbf3fa2235401528423f /sphinx/util | |
parent | 6ca7c1c579c6857985a5e8faae64a77b32dc6098 (diff) |
autodoc: an imported TypeVar is not resolved (refs: #8415)
So far, a TypeVar is rendered without module name. As a result, it
could not be resolved if it is imported from other modules. This
prepends its module name and make it resolvable. This is available
only in Python 3.7 or above.
As a side effect, all of TypeVars are displayed with module name. It
should be fixed in latter step (refs: #7119)
Diffstat (limited to 'sphinx/util')
-rw-r--r-- | sphinx/util/typing.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index d2bd03efd..afd2f805a 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -263,7 +263,10 @@ def stringify(annotation: Any) -> str: else: return annotation elif isinstance(annotation, TypeVar): - return annotation.__name__ + if annotation.__module__ == 'typing': + return annotation.__name__ + else: + return '.'.join([annotation.__module__, annotation.__name__]) elif inspect.isNewType(annotation): # Could not get the module where it defiend return annotation.__name__ |