autodoc_typehints_description_target: Rename returnvalue_and_documented_params to documented_params

This commit is contained in:
Takeshi KOMIYA 2022-04-03 22:42:44 +09:00
parent f731bf1999
commit fd42063725
4 changed files with 9 additions and 10 deletions

View File

@ -626,15 +626,15 @@ There are also config values that you can set:
When set to ``"documented"``, types will only be documented for a parameter
or a return value that is already documented by the docstring.
With ``"returnvalue_and_documented_params"``, parameter types will only be
annotated if the parameter is documented in the docstring. The return type is
always annotated (except if it is ``None``).
With ``"documented_params"``, parameter types will only be annotated if the
parameter is documented in the docstring. The return type is always
annotated (except if it is ``None``).
.. versionadded:: 4.0
.. versionadded:: 4.4
.. versionadded:: 5.0
New option ``'returnvalue_and_documented_params'`` is added.
New option ``'documented_params'`` is added.
.. confval:: autodoc_type_aliases

View File

@ -2882,7 +2882,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
app.add_config_value('autodoc_typehints', "signature", True,
ENUM("signature", "description", "none", "both"))
app.add_config_value('autodoc_typehints_description_target', 'all', True,
ENUM('all', 'documented', 'returnvalue_and_documented_params'))
ENUM('all', 'documented', 'documented_params'))
app.add_config_value('autodoc_type_aliases', {}, True)
app.add_config_value('autodoc_typehints_format', "short", 'env',
ENUM("fully-qualified", "short"))

View File

@ -60,8 +60,7 @@ def merge_typehints(app: Sphinx, domain: str, objtype: str, contentnode: Element
for field_list in field_lists:
if app.config.autodoc_typehints_description_target == "all":
modify_field_list(field_list, annotations[fullname])
elif (app.config.autodoc_typehints_description_target ==
"returnvalue_and_documented_params"):
elif app.config.autodoc_typehints_description_target == "documented_params":
augment_descriptions_with_types(
field_list, annotations[fullname], force_rtype=True
)

View File

@ -894,7 +894,7 @@ def test_autodoc_typehints_description_no_undoc(app):
@pytest.mark.sphinx('text', testroot='ext-autodoc',
confoverrides={'autodoc_typehints': "description",
'autodoc_typehints_description_target': 'returnvalue_and_documented_params'})
'autodoc_typehints_description_target': 'documented_params'})
def test_autodoc_typehints_description_no_undoc_doc_rtype(app):
# No :type: will be injected for `incr`, which does not have a description
# for its parameters or its return, just :rtype: will be injected due to
@ -1010,7 +1010,7 @@ def test_autodoc_typehints_description_with_documented_init_no_undoc(app):
@pytest.mark.sphinx('text', testroot='ext-autodoc',
confoverrides={'autodoc_typehints': "description",
'autodoc_typehints_description_target': 'returnvalue_and_documented_params'})
'autodoc_typehints_description_target': 'documented_params'})
def test_autodoc_typehints_description_with_documented_init_no_undoc_doc_rtype(app):
# see test_autodoc_typehints_description_with_documented_init_no_undoc
# returnvalue_and_documented_params should not change class or method