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

Report underlying type information for NewType and TypeVar #8460

Closed
anselor opened this issue Nov 20, 2020 · 4 comments
Closed

Report underlying type information for NewType and TypeVar #8460

anselor opened this issue Nov 20, 2020 · 4 comments
Labels
extensions:autodoc type:enhancement enhance or introduce a new feature
Milestone

Comments

@anselor
Copy link

anselor commented Nov 20, 2020

Is your feature request related to a problem? Please describe.
Autodoc for NewType and TypeVar report the name of the type and the developer doc-comments but doesn't report the type metadata.

Describe the solution you'd like
For NewType I'd expect it to report the underlying type.
For example:
MyInt = NewType('MyInt', int) should report in the generated docs that the underlying type is int.

ForTypeVar there are multiple attributes. If there's bound type information, that should be reported. Additionally, it should report whether the type is invariant, covariant, or contravariant. As a bonus, cross-linking between invariant, covariant, or contravariant TypeVar declarations for the same underlying type.

Describe alternatives you've considered
The alternative would be for the developer to manually document the type information they've already declared - which seems redundant since this should be easy to resolve.

Additional context

@anselor anselor added the type:enhancement enhance or introduce a new feature label Nov 20, 2020
@tk0miya
Copy link
Member

tk0miya commented Nov 21, 2020

Thank you for posting. I'll take a look at NewType from now on.

ForTypeVar there are multiple attributes. If there's bound type information, that should be reported. Additionally, it should report whether the type is invariant, covariant, or contravariant.

Now autodoc support to show attributes of TypeVar now. Do you know this?
https://github.com/sphinx-doc/sphinx/blob/3.x/tests/test_ext_autodoc.py#L1729-L1761

@tk0miya tk0miya added this to the 3.4.0 milestone Nov 21, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Nov 21, 2020
… is broken

A custom type defined by typing.NewType was rendered as a function
because the generated type is a function having special attributes.
This renders it as a variable.

Note: The module name where the NewType object defined is lost on
generating it.  So it is hard to make cross-reference for these custom
types.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Nov 21, 2020
…NewType

A custom type defined by typing.NewType was rendered as a function
because the generated type is a function having special attributes.
This renders it as a variable.

Note: The module name where the NewType object defined is lost on
generating it.  So it is hard to make cross-reference for these custom
types.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Nov 21, 2020
…NewType

A custom type defined by typing.NewType was rendered as a function
because the generated type is a function having special attributes.
This renders it as a variable.

Note: The module name where the NewType object defined is lost on
generating it.  So it is hard to make cross-reference for these custom
types.
tk0miya added a commit to tk0miya/sphinx that referenced this issue Nov 21, 2020
…NewType

A custom type defined by typing.NewType was rendered as a function
because the generated type is a function having special attributes.
This renders it as a variable.

Note: The module name where the NewType object defined is lost on
generating it.  So it is hard to make cross-reference for these custom
types.
tk0miya added a commit that referenced this issue Nov 22, 2020
Fix #8460: autodoc: Support custom types defined by typing.NewType
@tk0miya tk0miya reopened this Nov 22, 2020
@tk0miya
Copy link
Member

tk0miya commented Nov 22, 2020

Now I implement the support of NewTypes. It enables to render NewType variables in Sphinx. But referencing is still not working because NewType objects do not know where the type is defined.

@tk0miya
Copy link
Member

tk0miya commented Nov 22, 2020

Additionally, I noticed autodata and autoattribute directives does not support displaying the type information of TypeVars. So I'll post a fix soon.

tk0miya added a commit that referenced this issue Nov 23, 2020
Fix #8460: autodata directive does not display the detail of TypeVars
@tk0miya tk0miya reopened this Nov 23, 2020
@tk0miya
Copy link
Member

tk0miya commented Dec 13, 2020

Now autodoc supports NewType variables. So I'm closing this. About better output for TypeVars, please let me know if you find a nice idea!

@tk0miya tk0miya closed this as completed Dec 13, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 17, 2021
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

2 participants