diff --git a/CHANGES.rst b/CHANGES.rst index 915f35c4014..32c2e40586a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -96,6 +96,9 @@ Bugs fixed file URL (user-defined base URL of an intersphinx project are left untouched even if they end with double forward slashes). Patch by Bénédikt Tran. +* #12797: Fix + ``TypeError: Some type variables (...) are not listed in Generic[...]`` + when inheriting from both Generic and autodoc mocked class. Testing ------- diff --git a/sphinx/ext/autodoc/mock.py b/sphinx/ext/autodoc/mock.py index 265f45057b0..bed6331fd4b 100644 --- a/sphinx/ext/autodoc/mock.py +++ b/sphinx/ext/autodoc/mock.py @@ -29,6 +29,7 @@ class _MockObject: __name__ = '' __sphinx_mock__ = True __sphinx_decorator_args__: tuple[Any, ...] = () + __sphinx_empty_attrs__ = ('__typing_subst__',) def __new__(cls, *args: Any, **kwargs: Any) -> Any: if len(args) == 3 and isinstance(args[1], tuple): @@ -59,6 +60,8 @@ def __getitem__(self, key: Any) -> _MockObject: return _make_subclass(str(key), self.__display_name__, self.__class__)() def __getattr__(self, key: str) -> _MockObject: + if key in self.__sphinx_empty_attrs__: + return self.__getattribute__(key) return _make_subclass(key, self.__display_name__, self.__class__)() def __call__(self, *args: Any, **kwargs: Any) -> Any: