[ty] Report duplicate Protocol or Generic base classes with [duplicate-base], not [inconsistent-mro] (#17971)

This commit is contained in:
Alex Waygood 2025-05-08 23:41:22 +01:00 committed by GitHub
parent 4d81a41107
commit 9b694ada82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 7 deletions

View file

@ -19,6 +19,16 @@ reveal_type(generic_context(SingleTypevar)) # revealed: tuple[T]
reveal_type(generic_context(MultipleTypevars)) # revealed: tuple[T, S]
```
Inheriting from `Generic` multiple times yields a `duplicate-base` diagnostic, just like any other
class:
```py
class Bad(Generic[T], Generic[T]): ... # error: [duplicate-base]
# TODO: should emit an error (fails at runtime)
class AlsoBad(Generic[T], Generic[S]): ...
```
You cannot use the same typevar more than once.
```py

View file

@ -35,7 +35,7 @@ Just like for any other class base, it is an error for `Protocol` to appear mult
class's bases:
```py
class Foo(Protocol, Protocol): ... # error: [inconsistent-mro]
class Foo(Protocol, Protocol): ... # error: [duplicate-base]
reveal_type(Foo.__mro__) # revealed: tuple[<class 'Foo'>, Unknown, <class 'object'>]
```