Skip to content

Detect mix of generic type parameters and Generic subclass #15620

@ntBre

Description

@ntBre
>>> from typing import TypeVar
>>> T = TypeVar("T")
>>> class Foo[S](Generic[T]): ...
... 
Traceback (most recent call last):
  File "<python-input-13>", line 1, in <module>
    class Foo[S](Generic[T]): ...
  File "<python-input-13>", line 1, in <generic parameters of Foo>
    class Foo[S](Generic[T]): ...
  File "/Users/alexw/.pyenv/versions/3.13.1/lib/python3.13/typing.py", line 1279, in _generic_init_subclass
    raise TypeError(
        "Cannot inherit from Generic[...] multiple times.")
TypeError: Cannot inherit from Generic[...] multiple times.

Originally posted by @AlexWaygood in #15565 (comment)

Metadata

Metadata

Assignees

Labels

acceptedReady for implementationruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions