mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add the `autodoc_use_type_comments
` option (#13269)
This commit is contained in:
parent
44891a4eef
commit
bde37bec27
@ -65,6 +65,11 @@ Features added
|
||||
and rename the :rst:dir:`autosummary` directive's ``nosignatures``option
|
||||
to :rst:dir:`no-signatures``.
|
||||
Patch by Adam Turner.
|
||||
* #13269: Added the option to disable the use of type comments in
|
||||
via the new :confval:`autodoc_use_type_comments` option,
|
||||
which defaults to ``True`` for backwards compatibility.
|
||||
The default will change to ``False`` in Sphinx 10.
|
||||
Patch by Adam Turner.
|
||||
|
||||
Bugs fixed
|
||||
----------
|
||||
|
@ -1230,6 +1230,26 @@ There are also config values that you can set:
|
||||
Added as an experimental feature. This will be integrated into autodoc core
|
||||
in the future.
|
||||
|
||||
.. confval:: autodoc_use_type_comments
|
||||
:type: :code-py:`bool`
|
||||
:default: :code-py:`True`
|
||||
|
||||
Attempt to read ``# type: ...`` comments from source code
|
||||
to supplement missing type annotations, if True.
|
||||
|
||||
This can be disabled if your source code does not use type comments,
|
||||
for example if it exclusively uses type annotations or
|
||||
does not use type hints of any kind.
|
||||
|
||||
.. versionadded:: 8.2
|
||||
|
||||
Added the option to disable the use of type comments in
|
||||
via the new :confval:`!autodoc_use_type_comments` option,
|
||||
which defaults to :code-py:`True` for backwards compatibility.
|
||||
The default will change to :code-py:`False` in Sphinx 10.
|
||||
|
||||
.. xref RemovedInSphinx10Warning
|
||||
|
||||
.. confval:: autodoc_warningiserror
|
||||
:type: :code-py:`bool`
|
||||
:default: :code-py:`True`
|
||||
|
@ -131,6 +131,9 @@ def update_annotations_using_type_comments(
|
||||
app: Sphinx, obj: Any, bound_method: bool
|
||||
) -> None:
|
||||
"""Update annotations info of *obj* using type_comments."""
|
||||
if not app.config.autodoc_use_type_comments:
|
||||
return
|
||||
|
||||
try:
|
||||
type_sig = get_type_comment(obj, bound_method)
|
||||
if type_sig:
|
||||
@ -152,6 +155,9 @@ def update_annotations_using_type_comments(
|
||||
|
||||
|
||||
def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
app.add_config_value(
|
||||
'autodoc_use_type_comments', True, 'env', types=frozenset({bool})
|
||||
)
|
||||
app.connect(
|
||||
'autodoc-before-process-signature', update_annotations_using_type_comments
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user