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

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
3 changes: 3 additions & 0 deletions sphinx/ext/autodoc/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down