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 when subclassing Generic, see: https://github.com/python/cpython/blob/31d3836f26096f9503ca68f4e89d927bc1e060cd/Lib/typing.py#L1175

Especially this line in the utility function to gather TypeVars should not be True: elif hasattr(t, '__typing_subst__'):.
But, as it is a mock object, hasattr will return True which will raise an error on Python 3.11/12. (3.10 is fine). I did not test 3.13 or 3.14.

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.

@jfbu
Copy link
Contributor

jfbu commented Sep 7, 2025

I relaunched the failed Docutils HEAD test and it now passes with current Docutils revision. LaTeX failure was only a duplicate because it uses Docutils HEAD since some time.

See #13845 (comment) and #13845 (comment) for context.

@Daraan
Copy link
Author

Daraan commented Sep 8, 2025

I relaunched the failed Docutils HEAD test and it now passes with current Docutils revision. LaTeX failure was only a duplicate because it uses Docutils HEAD since some time.

See #13845 (comment) and #13845 (comment) for context.

Thanks for the notice. Mind to do a review :) ?

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[...]
2 participants