summaryrefslogtreecommitdiff
path: root/sphinx/util/inspect.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/util/inspect.py')
-rw-r--r--sphinx/util/inspect.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index 9beec4f25..b47940813 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -676,10 +676,16 @@ def stringify_signature(sig: inspect.Signature, show_annotation: bool = True,
unqualified_typehints: bool = False) -> str:
"""Stringify a Signature object.
- :param show_annotation: Show annotation in result
- :param unqualified_typehints: Show annotations as unqualified
+ :param show_annotation: If enabled, show annotations on the signature
+ :param show_return_annotation: If enabled, show annotation of the return value
+ :param unqualified_typehints: If enabled, show annotations as unqualified
(ex. io.StringIO -> StringIO)
"""
+ if unqualified_typehints:
+ mode = 'smart'
+ else:
+ mode = 'fully-qualified'
+
args = []
last_kind = None
for param in sig.parameters.values():
@@ -702,7 +708,7 @@ def stringify_signature(sig: inspect.Signature, show_annotation: bool = True,
if show_annotation and param.annotation is not param.empty:
arg.write(': ')
- arg.write(stringify_annotation(param.annotation, unqualified_typehints))
+ arg.write(stringify_annotation(param.annotation, mode))
if param.default is not param.empty:
if show_annotation and param.annotation is not param.empty:
arg.write(' = ')
@@ -722,7 +728,7 @@ def stringify_signature(sig: inspect.Signature, show_annotation: bool = True,
show_return_annotation is False):
return '(%s)' % ', '.join(args)
else:
- annotation = stringify_annotation(sig.return_annotation, unqualified_typehints)
+ annotation = stringify_annotation(sig.return_annotation, mode)
return '(%s) -> %s' % (', '.join(args), annotation)