Skip to content

Conversation

Daraan
Copy link

@Daraan Daraan commented Aug 30, 2025

Purpose

When subclassing a MockObject and typing.Generic the mock object will be detected as a TypeVar by typing

https://github.com/python/cpython/blob/31d3836f26096f9503ca68f4e89d927bc1e060cd/Lib/typing.py#L1175

Especially this line should not be True: elif hasattr(t, '__typing_subst__'):, but as it is a mock object it currently is True which will raise an error on Python 3.11/12. (3.10 is fine). I did not test 3.13 or 3.14.

https://github.com/python/cpython/blob/31d3836f26096f9503ca68f4e89d927bc1e060cd/Lib/typing.py#L297C1-L297C45

References

Fixes #12797
Continues PR #12850 by @IkorJefocur with a slight reinterpretation and added tests.

@Daraan Daraan changed the title Fix generic mock [autodoc] Fix subclassing a MockObject together with typing.Generic Aug 30, 2025
@Daraan
Copy link
Author

Daraan commented Aug 30, 2025

I'll appreciate input on the failing Docutils HEAD and LaTeX tests if they are relevant and how to address them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: Some type variables (...) are not listed in Generic[...]
1 participant