mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
[ty] Report duplicate Protocol
or Generic
base classes with [duplicate-base]
, not [inconsistent-mro]
(#17971)
This commit is contained in:
parent
4d81a41107
commit
9b694ada82
4 changed files with 27 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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'>]
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue