Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close #9075: autodoc: Add a config variable autodoc_unqualified_typehints #9931

Merged
merged 4 commits into from Dec 11, 2021

Conversation

tk0miya
Copy link
Member

@tk0miya tk0miya commented Dec 2, 2021

Feature or Bugfix

  • Feature

Purpose

Now python domain supports the "~" prefix at the beginning of the
typehints of the function signatures:

  .. py:function:: func(x: ~typing.Dict)

It's rescognized as the same as python reference roles do
(ex. :py:class:`~typing.Dict`).
@tk0miya tk0miya added type:enhancement enhance or introduce a new feature extensions:autodoc labels Dec 2, 2021
@tk0miya tk0miya added this to the 4.4.0 milestone Dec 2, 2021
' :type: int',
'',
'',
'.. py:class:: Math(s: str, o: ~typing.Optional[~typing.Any] = None)',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internally, autodoc generates a typehints leading ~ if the option is enabled. This is a special notation to suppress prefix (modname and leading class name) of the typehint. It's like the ~ of :py:class: role (ex. :py:class:`~io.StringIO` ).

.. confval:: autodoc_unqualified_typehints

If True, the leading module names of typehints of function signatures (ex. ``io.StringIO`` ->
`StringIO``). Defaults to False.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep compatibility, I'll disable this feature by default during 4.x. And I'd like to enable this since 5.x.

@tk0miya tk0miya force-pushed the 9075_autodoc_unqualified_typehints branch from 859d1e4 to f50c26e Compare December 2, 2021 18:02
To make the generated function signatures simple, this adds a new
parameter `smartref` to sphinx.util.typing:stringify() to suppress the
leading module name from typehints.
To make the generated function signatures simple, this adds a new
parameter `unqualified_typehints` to sphinx.util.inspect:
stringify_signature() to suppress the leading module name of
typehints.
…fied_typehints

If autodoc_unqualified_typehints feature enabled, autodoc suppresses the
leading module names of typehints of function signatures (ex.
`io.StringIO` -> `StringIO`)
@tk0miya tk0miya force-pushed the 9075_autodoc_unqualified_typehints branch from f50c26e to c71ff1c Compare December 3, 2021 09:05
sphinx/util/typing.py Outdated Show resolved Hide resolved
@tk0miya tk0miya merged commit d3162d1 into sphinx-doc:4.x Dec 11, 2021
@tk0miya tk0miya deleted the 9075_autodoc_unqualified_typehints branch December 11, 2021 01:59
tk0miya added a commit to tk0miya/sphinx that referenced this pull request Dec 18, 2021
tk0miya added a commit to tk0miya/sphinx that referenced this pull request Dec 18, 2021
tk0miya added a commit that referenced this pull request Dec 19, 2021
doc: Update explanation of autodoc_unqualified_typehints (ref: #9931)
@tk0miya
Copy link
Member Author

tk0miya commented Dec 19, 2021

I discussed the option name with @shimizukawa in the hack day. And he proposed to me to rename this option to use "short name" instead of "unqualified" because "unqualified" is not easy to understand.

tk0miya added a commit to tk0miya/sphinx that referenced this pull request Dec 24, 2021
tk0miya added a commit that referenced this pull request Dec 25, 2021
autodoc: Rename autodoc_unqualified_typehints to autodoc_typehints_format (refs: #9931)
AA-Turner pushed a commit to AA-Turner/sphinx that referenced this pull request Dec 29, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
extensions:autodoc type:enhancement enhance or introduce a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant