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
Close #9075: autodoc: Add a config variable autodoc_unqualified_typehints #9931
Conversation
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`).
tests/test_ext_autodoc_configs.py
Outdated
' :type: int', | ||
'', | ||
'', | ||
'.. py:class:: Math(s: str, o: ~typing.Optional[~typing.Any] = None)', |
There was a problem hiding this comment.
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`
).
doc/usage/extensions/autodoc.rst
Outdated
.. confval:: autodoc_unqualified_typehints | ||
|
||
If True, the leading module names of typehints of function signatures (ex. ``io.StringIO`` -> | ||
`StringIO``). Defaults to False. |
There was a problem hiding this comment.
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.
859d1e4
to
f50c26e
Compare
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`)
f50c26e
to
c71ff1c
Compare
doc: Update explanation of autodoc_unqualified_typehints (ref: #9931)
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. |
autodoc: Rename autodoc_unqualified_typehints to autodoc_typehints_format (refs: #9931)
Feature or Bugfix
Purpose
leading module names of typehints of function signatures (ex.
io.StringIO
->StringIO
)