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.
This commit is contained in:
Takeshi KOMIYA
2020-11-08 13:17:28 +09:00
parent e2c969c495
commit 6d1cafe7bd
4 changed files with 8 additions and 6 deletions

View File

@@ -490,7 +490,7 @@ def test_autodoc_typehints_signature(app):
'.. py:module:: target.typehints',
'',
'',
'.. py:class:: Math(s: str, o: Any = None)',
'.. py:class:: Math(s: str, o: Optional[Any] = None)',
' :module: target.typehints',
'',
'',