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

TypeError: Some type variables (...) are not listed in Generic[...] #12797

Open
IkorJefocur opened this issue Aug 17, 2024 · 3 comments · May be fixed by #12850
Open

TypeError: Some type variables (...) are not listed in Generic[...] #12797

IkorJefocur opened this issue Aug 17, 2024 · 3 comments · May be fixed by #12850

Comments

@IkorJefocur
Copy link

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

@electric-coder
Copy link

Possibly related #12512 you might want to take a look at autodoc_pydantic.

@IkorJefocur
Copy link
Author

@electric-coder It's not a pydantic-related issue, it's more generic. Pydantic here just for example. If I want to inherit any mocked library's class and define any generics on it I will get the same error.

@electric-coder
Copy link

electric-coder commented Aug 17, 2024

@IkorJefocur generics have caused a number of problems #11327 I'm lucky not to have run into any of them. As an end-user I'd advise you to try narrowing down the problem because mock, inheritance, generics and pydantic are known to cause problems individually, so I'm not surprised that putting them all together is causing an error. In my experience just because something works at run time it does not mean it won't break 3rd party tooling.

It's not a pydantic-related issue

Can you test it by mocking one of your own moduies and adjust the minimum reproducible example? It would be helpful in narrowing down the issue, the less complexity the better.

IkorJefocur pushed a commit to IkorJefocur/sphinx that referenced this issue Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants