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-12-02 15:13:48 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-12-03 12:05:49 +0300
commit5aa6cbbca85ddc3fe5dd93d45a7cf5073db2f334 (patch)
tree4d1cac4c8a306373961c27885a9caa911a38b41e /sphinx/util
parent80f79aef919d54fec1fcf6edcda7f5de26e70873 (diff)
Add `unqualified_typehints` parameter to stringify_signature()
To make the generated function signatures simple, this adds a new parameter `unqualified_typehints` to sphinx.util.inspect: stringify_signature() to suppress the leading module name of typehints.
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/inspect.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index 24ea49ae0..3a282ad7c 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -744,10 +744,13 @@ def evaluate_signature(sig: inspect.Signature, globalns: Dict = None, localns: D
def stringify_signature(sig: inspect.Signature, show_annotation: bool = True,
- show_return_annotation: bool = True) -> str:
+ show_return_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
+ (ex. io.StringIO -> StringIO)
"""
args = []
last_kind = None
@@ -771,7 +774,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))
+ arg.write(stringify_annotation(param.annotation, unqualified_typehints))
if param.default is not param.empty:
if show_annotation and param.annotation is not param.empty:
arg.write(' = ')
@@ -791,7 +794,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)
+ annotation = stringify_annotation(sig.return_annotation, unqualified_typehints)
return '(%s) -> %s' % (', '.join(args), annotation)