Navigation Menu

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

autodoc add_module_names equivalent for arguments #9075

Closed
RuRo opened this issue Apr 10, 2021 · 8 comments
Closed

autodoc add_module_names equivalent for arguments #9075

RuRo opened this issue Apr 10, 2021 · 8 comments
Labels
extensions:autodoc type:enhancement enhance or introduce a new feature
Milestone

Comments

@RuRo
Copy link
Contributor

RuRo commented Apr 10, 2021

The add_module_names = False configuration seems to only affect the class/function/attribute header names.
The type hints are still always rendered as fully qualified names.

mypackage/mymodule.py:

class MyClass:
    """Whatever 1."""
    pass


def foo(arg: MyClass):
    """Whatever 2."""
    pass

conf.py:

# ...
add_module_names = False
# ...

index.rst:

mypackage.mymodule module
=========================

.. automodule:: mypackage.mymodule
   :members:
   :undoc-members:
   :show-inheritance:

Expected documentation:

foo(arg: MyClass)
    Whatever 2.

Actual documentation:

foo(arg: mypackage.mymodule.MyClass)
    Whatever 2.

Describe the solution you'd like

I would be OK with any of the following:

add_module_names = False # now affects type annotations too
# or
add_type_module_names = False # new sphinx config option (name up for debate)
# or
autodoc_add_module_names = False # new autodoc config option (name up for debate)

Describe alternatives you've considered

There's a StackOverflow post which suggests using the autodoc_docstring_signature option to manually specify the function signature. This is not really a viable solution in my opinion.

@RuRo RuRo added the type:enhancement enhance or introduce a new feature label Apr 10, 2021
@tk0miya tk0miya added this to the 4.1.0 milestone May 16, 2021
@tk0miya
Copy link
Member

tk0miya commented May 16, 2021

+1 for adding a new confval only for autodoc. It would be nice if we can give better name to it. I feel "add_module_names" is a bit ambiguous and difficult to understand its behavior from the name.

@RuRo
Copy link
Contributor Author

RuRo commented May 16, 2021

To be clear, the add_module_names confval already exists. It's just that it doesn't affect parameter types for some reason.

@tk0miya
Copy link
Member

tk0miya commented May 16, 2021

Sorry for confuse. I know that. I thought it's better to separate the confval for autodoc and python-domain.

@tk0miya
Copy link
Member

tk0miya commented May 16, 2021

Just FYI: Sphinx-4.0 provides a new configuration python_use_unqualified_type_names. It suppresses the module name if hyperlinks can be resolved.

@felix-hilden
Copy link

So does this mean that the proposed add_module_names configuration is completely unnecessary?

@RuRo
Copy link
Contributor Author

RuRo commented May 25, 2021

My understanding is that python_use_unqualified_type_names only works with resolved refs and only for the python domain. Although, I would personally consider this issue fixed if python_use_unqualified_type_names would also work for unresolved refs.

@felix-hilden
Copy link

Oh that's a fair point! Yep.

@RuRo
Copy link
Contributor Author

RuRo commented Jul 2, 2021

Also, not sure if this deserves a separate issue/feature request, but one more place where sphinx currently produces fully qualified names is in the package/module headings generated with apidoc. So for example, if you have

foo/__init__.py
foo/bar/__init__.py
foo/bar/baz.py

you will get the documentation for

foo package
 - foo.bar package
    - foo.bar.baz module

instead of

foo package
 - bar package
    - baz module

The FQN version is kind of redundant, since the parent packages of bar and baz are already obvious from the ToC. And with longer package/module names, this can lead to really ugly wrapping in the sidebar ToC.

@tk0miya tk0miya modified the milestones: 4.1.0, 4.2.0 Jul 10, 2021
@tk0miya tk0miya modified the milestones: 4.2.0, 4.3.0 Sep 12, 2021
@tk0miya tk0miya modified the milestones: 4.3.0, 4.4.0 Nov 8, 2021
tk0miya added a commit to tk0miya/sphinx that referenced this issue Dec 2, 2021
…fied_typehints

If autodoc_unqualified_typehints feature enabled, autodoc suppresses the
leading module names of typehints of function signatures (ex.
``io.StringIO`` -> (`StringIO``)
tk0miya added a commit to tk0miya/sphinx that referenced this issue Dec 2, 2021
…fied_typehints

If autodoc_unqualified_typehints feature enabled, autodoc suppresses the
leading module names of typehints of function signatures (ex.
`io.StringIO` -> `StringIO`)
tk0miya added a commit to tk0miya/sphinx that referenced this issue Dec 2, 2021
…fied_typehints

If autodoc_unqualified_typehints feature enabled, autodoc suppresses the
leading module names of typehints of function signatures (ex.
`io.StringIO` -> `StringIO`)
tk0miya added a commit that referenced this issue Dec 11, 2021
Close #9075: autodoc: Add a config variable autodoc_unqualified_typehints
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 1, 2022
The default value of :confval:`autodoc_typehints_format` is changed to
``'smart'``.  It will suppress the leading module names of typehints
(ex. ``io.StringIO`` -> ``StringIO``).

refs: sphinx-doc#9075
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 1, 2022
The default value of autodoc_typehints_format configuration is changed
to `'smart'`.  It will suppress the leading module names of typehints
(ex. `io.StringIO` -> `StringIO`).

refs: sphinx-doc#9075
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 2, 2022
The default value of autodoc_typehints_format configuration is changed
to `'smart'`.  It will suppress the leading module names of typehints
(ex. `io.StringIO` -> `StringIO`).

refs: sphinx-doc#9075
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 11, 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

No branches or pull requests

3 participants