Skip to content

Commit

Permalink
autodoc: Rename autodoc_unqualified_typehints to autodoc_typehints_fo…
Browse files Browse the repository at this point in the history
…rmat (refs: sphinx-doc#9931)
  • Loading branch information
tk0miya committed Dec 24, 2021
1 parent 048fd80 commit a87153c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Deprecated
Features added
--------------

* #9075: autodoc: Add a config variable :confval:`autodoc_unqualified_typehints`
* #9075: autodoc: Add a config variable :confval:`autodoc_typehints_format`
to suppress the leading module names of typehints of function signatures (ex.
``io.StringIO`` -> ``StringIO``)
* #9831: Autosummary now documents only the members specified in a module's
Expand Down
11 changes: 8 additions & 3 deletions doc/usage/extensions/autodoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -662,10 +662,15 @@ There are also config values that you can set:
.. __: https://mypy.readthedocs.io/en/latest/kinds_of_types.html#type-aliases
.. versionadded:: 3.3

.. confval:: autodoc_unqualified_typehints
.. confval:: autodoc_typehints_format

If True, the leading module names of typehints of function signatures are
removed (ex. ``io.StringIO`` -> ``StringIO``). Defaults to False.
This value controls the format of typehints. The setting takes the
following values:

* ``'fully-qualified'`` -- Show the module name and its name of typehints
(default)
* ``'short'`` -- Suppress the leading module names of the typehints
(ex. ``io.StringIO`` -> ``StringIO``)

.. versionadded:: 4.4

Expand Down
15 changes: 8 additions & 7 deletions sphinx/ext/autodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ def can_document_member(cls, member: Any, membername: str, isattr: bool, parent:
def format_args(self, **kwargs: Any) -> str:
if self.config.autodoc_typehints in ('none', 'description'):
kwargs.setdefault('show_annotation', False)
if self.config.autodoc_unqualified_typehints:
if self.config.autodoc_typehints_format == "short":
kwargs.setdefault('unqualified_typehints', True)

try:
Expand Down Expand Up @@ -1325,7 +1325,7 @@ def add_directive_header(self, sig: str) -> None:
self.add_line(' :async:', sourcename)

def format_signature(self, **kwargs: Any) -> str:
if self.config.autodoc_unqualified_typehints:
if self.config.autodoc_typehints_format == "short":
kwargs.setdefault('unqualified_typehints', True)

sigs = []
Expand Down Expand Up @@ -1566,7 +1566,7 @@ def get_user_defined_function_or_method(obj: Any, attr: str) -> Any:
def format_args(self, **kwargs: Any) -> str:
if self.config.autodoc_typehints in ('none', 'description'):
kwargs.setdefault('show_annotation', False)
if self.config.autodoc_unqualified_typehints:
if self.config.autodoc_typehints_format == "short":
kwargs.setdefault('unqualified_typehints', True)

try:
Expand All @@ -1589,7 +1589,7 @@ def format_signature(self, **kwargs: Any) -> str:
# do not show signatures
return ''

if self.config.autodoc_unqualified_typehints:
if self.config.autodoc_typehints_format == "short":
kwargs.setdefault('unqualified_typehints', True)

sig = super().format_signature()
Expand Down Expand Up @@ -2120,7 +2120,7 @@ def import_object(self, raiseerror: bool = False) -> bool:
def format_args(self, **kwargs: Any) -> str:
if self.config.autodoc_typehints in ('none', 'description'):
kwargs.setdefault('show_annotation', False)
if self.config.autodoc_unqualified_typehints:
if self.config.autodoc_typehints_format == "short":
kwargs.setdefault('unqualified_typehints', True)

try:
Expand Down Expand Up @@ -2172,7 +2172,7 @@ def document_members(self, all_members: bool = False) -> None:
pass

def format_signature(self, **kwargs: Any) -> str:
if self.config.autodoc_unqualified_typehints:
if self.config.autodoc_typehints_format == "short":
kwargs.setdefault('unqualified_typehints', True)

sigs = []
Expand Down Expand Up @@ -2848,7 +2848,8 @@ def setup(app: Sphinx) -> Dict[str, Any]:
app.add_config_value('autodoc_typehints_description_target', 'all', True,
ENUM('all', 'documented'))
app.add_config_value('autodoc_type_aliases', {}, True)
app.add_config_value('autodoc_unqualified_typehints', False, 'env')
app.add_config_value('autodoc_typehints_format', "fully-qualified", 'env',
ENUM("fully-qualified", "short"))
app.add_config_value('autodoc_warningiserror', True, True)
app.add_config_value('autodoc_inherit_docstrings', True, True)
app.add_event('autodoc-before-process-signature')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ext_autodoc_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,8 +1143,8 @@ def test_autodoc_typehints_description_and_type_aliases(app):


@pytest.mark.sphinx('html', testroot='ext-autodoc',
confoverrides={'autodoc_unqualified_typehints': True})
def test_autodoc_unqualified_typehints(app):
confoverrides={'autodoc_typehints_format': "short"})
def test_autodoc_typehints_format_short(app):
if sys.version_info < (3, 7):
Any = 'Any'
else:
Expand Down

0 comments on commit a87153c

Please sign in to comment.