diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2022-02-14 03:03:40 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2022-02-14 03:03:40 +0900 |
commit | 8b23f6db12d9fcdb6e1ca2015ea32e3e2e1fbdb6 (patch) | |
tree | 45c07e0a74fcace45cfb43d7491bab9a98f88087 /sphinx/util | |
parent | d7c6fa853ce433640331deab837b3a0c0edb3c9d (diff) | |
parent | 07110b7557a552ecfe702bdd6a2d2f9685cb1af9 (diff) | |
download | sphinx-git-8b23f6db12d9fcdb6e1ca2015ea32e3e2e1fbdb6.tar.gz |
Merge commit '07110b7557a552ecfe702bdd6a2d2f9685cb1af9'
Diffstat (limited to 'sphinx/util')
-rw-r--r-- | sphinx/util/typing.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index d9b63e046..5cd0c230e 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -116,6 +116,7 @@ def restify(cls: Optional[Type], mode: str = 'fully-qualified-except-typing') -> 'smart' Show the name of the annotation. """ + from sphinx.ext.autodoc.mock import ismock, ismockmodule # lazy loading from sphinx.util import inspect # lazy loading if mode == 'smart': @@ -130,6 +131,10 @@ def restify(cls: Optional[Type], mode: str = 'fully-qualified-except-typing') -> return '...' elif isinstance(cls, str): return cls + elif ismockmodule(cls): + return ':py:class:`%s%s`' % (modprefix, cls.__name__) + elif ismock(cls): + return ':py:class:`%s%s.%s`' % (modprefix, cls.__module__, cls.__name__) elif cls in INVALID_BUILTIN_CLASSES: return ':py:class:`%s%s`' % (modprefix, INVALID_BUILTIN_CLASSES[cls]) elif inspect.isNewType(cls): @@ -335,6 +340,7 @@ def stringify(annotation: Any, mode: str = 'fully-qualified-except-typing') -> s 'fully-qualified' Show the module name and qualified name of the annotation. """ + from sphinx.ext.autodoc.mock import ismock, ismockmodule # lazy loading from sphinx.util import inspect # lazy loading if mode == 'smart': @@ -364,6 +370,10 @@ def stringify(annotation: Any, mode: str = 'fully-qualified-except-typing') -> s return repr(annotation) elif annotation is NoneType: return 'None' + elif ismockmodule(annotation): + return modprefix + annotation.__name__ + elif ismock(annotation): + return modprefix + '%s.%s' % (annotation.__module__, annotation.__name__) elif annotation in INVALID_BUILTIN_CLASSES: return modprefix + INVALID_BUILTIN_CLASSES[annotation] elif str(annotation).startswith('typing.Annotated'): # for py310+ |