summaryrefslogtreecommitdiff
path: root/sphinx
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-11-08 13:17:28 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-11-10 02:41:58 +0900
commit6d1cafe7bd0ec10f453952b51aff80eb6f44c7b0 (patch)
treecbcfa3fa5e348132707d33dbdeda122f3571b721 /sphinx
parente2c969c4955662a8c5e4da8b77672aaaa7729359 (diff)
downloadsphinx-git-6d1cafe7bd0ec10f453952b51aff80eb6f44c7b0.tar.gz
autodoc: Add Optional[t] to annotation of function and method
As typing.get_type_hints() doing, this adds Optional[t] to type annotations if a default value equal to None is set. Note: this is default behavior of inspect.signature() since Python 3.10.
Diffstat (limited to 'sphinx')
-rw-r--r--sphinx/util/inspect.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index 1eaccb678..92c6ac7fb 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -470,10 +470,10 @@ def signature(subject: Callable, bound_method: bool = False, follow_wrapped: boo
raise
try:
- # Update unresolved annotations using ``get_type_hints()``.
+ # Resolve forwared reference annotations using ``get_type_hints()`` and type_aliases.
annotations = typing.get_type_hints(subject, None, type_aliases)
for i, param in enumerate(parameters):
- if isinstance(param.annotation, str) and param.name in annotations:
+ if param.name in annotations:
parameters[i] = param.replace(annotation=annotations[param.name])
if 'return' in annotations:
return_annotation = annotations['return']