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 doesn't handle TypeVars or document user-defined generic classes accurately #8219
Comments
Functional solution was demonstrated at Stack Overflow. EDIT: It worked for me due to old caches. After invalidating caches I confirm the problem in the question of the Environment Windows 10 |
I also added the additional options described in the Stack Overflow link and also continue to have this issue. I'm using the I also added this to
|
…lass is incorrect Inogre the signature of typing.Generic.__new__() to get correct a signature of the constructor from a subclass.
…lass is incorrect Ignore the signature of typing.Generic.__new__() to get correct a signature of the constructor from a subclass.
Please add a comment (starting with a colon) to the typevar. Then autodoc detects it automatically.
Now I posted #8229 to fix this.
I need time to fix this. Note: The arguments of |
I've not seen the |
It has been described at autoattribute's document. |
I'm still having issues with the first item. It looks like if my module is in a package, the reference to the typevar doesn't preserve the package name of the typevar alias and is unable to locate it. If I manually create a attribute in the global scope that matches the name of the typevar alias, then autodoc is able to locate that manually defined attribute. |
@anselor Could you file another issue with detailed information? It would be very helpful if there is an example code! |
…ass_is_not_shown Fix #8219: autodoc: Parameters for generic base class are not shown
Describe the bug
TypeVar aliases aren't resolved
When using automodule, if a TypeVar is used, the TypeVar isn't being recognized. With nitpick on, this warning is generated:
helloworld.py:docstring of helloworld.helloworld.MyGenericType.foo:: WARNING: py:class reference target not found: MyTypeVar
I can add it to the nitpick ignore list, but then all of the parameters that reference it aren't recognized and linked.
typing.Generic
type parameters for user-defined generic classes aren't documentedConstructor for user-defined generic classes are always
(*args, **kwargs)
instead of what's actually declared.To Reproduce
Simple doc file
index.rst
:Here's an example module
helloworld.py
:Expected behavior
Ideally:
TypeVar
definitions to be recognized as typesTypeVar
s passed totyping.Generic
Work-around for Item 1
This is less than ideal, but I can get the TypeVar to resolve by manually documenting it as an attribute like this:
Your project
I've included a simple example above
Screenshots
Here's the generated documentation:
Here's the generated output with the manual attribute work-around:
Environment info
Additional context
The text was updated successfully, but these errors were encountered: