mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 14:51:25 +00:00
[ty] Ban protocols from inheriting from non-protocol generic classes (#19941)
This commit is contained in:
parent
f4d8826428
commit
9ac39cee98
2 changed files with 15 additions and 10 deletions
|
@ -150,6 +150,14 @@ class AlsoInvalid(MyProtocol, OtherProtocol, NotAProtocol, Protocol): ...
|
|||
|
||||
# revealed: tuple[<class 'AlsoInvalid'>, <class 'MyProtocol'>, <class 'OtherProtocol'>, <class 'NotAProtocol'>, typing.Protocol, typing.Generic, <class 'object'>]
|
||||
reveal_type(AlsoInvalid.__mro__)
|
||||
|
||||
class NotAGenericProtocol[T]: ...
|
||||
|
||||
# error: [invalid-protocol] "Protocol class `StillInvalid` cannot inherit from non-protocol class `NotAGenericProtocol`"
|
||||
class StillInvalid(NotAGenericProtocol[int], Protocol): ...
|
||||
|
||||
# revealed: tuple[<class 'StillInvalid'>, <class 'NotAGenericProtocol[int]'>, typing.Protocol, typing.Generic, <class 'object'>]
|
||||
reveal_type(StillInvalid.__mro__)
|
||||
```
|
||||
|
||||
But two exceptions to this rule are `object` and `Generic`:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue