sphinx
sphinx copied to clipboard
TypeError: Some type variables (...) are not listed in Generic[...]
Describe the bug
Using autodoc extension with autodoc_mock_imports
configuration value, importing mocked module, then extending class from that module with generic on a new class causes exception when generating docs. Exception looks like this:
WARNING: [autosummary] failed to import main.
Possible hints:
* KeyError: 'main'
* ValueError: not enough values to unpack (expected 2, got 1)
* TypeError: Some type variables (pydantic.BaseModel) are not listed in Generic[T]
How to Reproduce
# conf.py
project = 'Test'
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary'
]
autosummary_generate = True
autodoc_mock_imports = ['pydantic']
# index.rst
Documentation
=============
.. autosummary::
:toctree: generated
:template: module.rst
main
# main.py
from pydantic import BaseModel # can be any class from any mocked module
class MyModel[T](BaseModel):
pass
Environment Information
Platform: linux; (Linux-6.1.99-1-MANJARO-x86_64-with-glibc2.39)
Python version: 3.12.4 (main, Jun 7 2024, 06:33:07) [GCC 14.1.1 20240522])
Python implementation: CPython
Sphinx version: 8.0.2
Docutils version: 0.21.2
Jinja2 version: 3.1.4
Pygments version: 2.18.0
Sphinx extensions
['sphinx.ext.autodoc', 'sphinx.ext.autosummary']
Additional context
No response