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

Add option for autodoc to show types with class-only (no module prefix) #9789

Conversation

gschwaer
Copy link
Contributor

@gschwaer gschwaer commented Oct 28, 2021

Feature or Bugfix

  • Feature

Purpose

  • Sometimes modules are used like packages in java, so you can have long redundant module prefixes and the type will be shown in the documentation as a very long string, e.g., Returns: com.mycompany.something.module.MyType.
  • This feature PR will add an option to autodoc
    app.add_config_value('autodoc_typehints_types_qualified', 'full', True,
                         ENUM('full', 'class-only'))
    
  • By default ("full"), everything stays as it is.
  • If "class-only" is used, types are shown in the documentation as __qualname__ and not __module__.__qualname__
    autodoc_typehints_types_qualified = "class-only"
    
  • Returns: com.mycompany.something.module.MyType -> Returns: MyType.
  • Links continue to work.

Detail

  • An example project can be found here.
  • This PR needs some input:
    • Is the way it is implemented ok for sphinx? (passing the config from sphinx.ext.autodoc.typehints to sphinx.util.typing)
    • What about the name autodoc_typehints_types_qualified? Is it clear enough?
  • TODO
    • A description in the documentation of sphinx.ext.autodoc is still missing.

Relates

  • This is a feature that agronholm/sphinx-autodoc-typehints called typehints_fully_qualified. But this extension has some issues and since sphinx.ext.autodoc now supports typehints it is obsolete IMO.

@gschwaer
Copy link
Contributor Author

gschwaer commented Nov 3, 2021

I found some other issues with documented types: #9813
I will close this PR until this is discussed.

@gschwaer gschwaer closed this Nov 3, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants