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 documented
-
Constructor for user-defined generic classes are always (*args, **kwargs) instead of what's actually declared.
To Reproduce
Simple doc file index.rst:
Hello World
===========
code docs
=========
.. automodule:: helloworld.helloworld
:members:
:undoc-members:
:show-inheritance:
Here's an example module helloworld.py:
from typing import Generic, TypeVar
MyTypeVar = TypeVar('MyTypeVar')
class MyGenericType(Generic[MyTypeVar]):
def __init__(self, param: MyTypeVar) -> None:
pass
def foo(self, param: MyTypeVar) -> None:
pass
Expected behavior
Ideally:
- I would expect
TypeVar definitions to be recognized as types
- Generic classes should document the
TypeVars passed to typing.Generic
- Constructor for generic classes should reflect the parameters declared in the constructor.
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:
.. py:attribute:: MyTypeVar
:type: TypeVar
:value: TypeVar('MyTypeVar')
This is the type used in MyGenericClass
.. automodule:: helloworld.helloworld
:members:
:undoc-members:
:show-inheritance:
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
- OS: Ubuntu 18.04, Ubuntu 20.04
- Python version: 3.6.9, 3.8.2
- Sphinx version: 3.1.2, 3.2.1
- Sphinx extensions: sphinx.ext.autodoc
- Extra tools: Viewing output on Chrome
Additional context
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: MyTypeVarI can add it to the nitpick ignore list, but then all of the parameters that reference it aren't recognized and linked.
typing.Generictype 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:
TypeVardefinitions to be recognized as typesTypeVars passed totyping.GenericWork-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