[red-knot] Detect (some) invalid protocols (#17488)

This commit is contained in:
Alex Waygood
2025-04-21 16:24:19 +01:00
committed by GitHub
parent 9ff4772a2c
commit 45b5dedee2
4 changed files with 76 additions and 19 deletions

View File

@@ -136,13 +136,13 @@ If `Protocol` is present in the bases tuple, all other bases in the tuple must b
or `TypeError` is raised at runtime when the class is created.
```py
# TODO: should emit `[invalid-protocol]`
# error: [invalid-protocol] "Protocol class `Invalid` cannot inherit from non-protocol class `NotAProtocol`"
class Invalid(NotAProtocol, Protocol): ...
# revealed: tuple[Literal[Invalid], Literal[NotAProtocol], typing.Protocol, typing.Generic, Literal[object]]
reveal_type(Invalid.__mro__)
# TODO: should emit an `[invalid-protocol`] error
# error: [invalid-protocol] "Protocol class `AlsoInvalid` cannot inherit from non-protocol class `NotAProtocol`"
class AlsoInvalid(MyProtocol, OtherProtocol, NotAProtocol, Protocol): ...
# revealed: tuple[Literal[AlsoInvalid], Literal[MyProtocol], Literal[OtherProtocol], Literal[NotAProtocol], typing.Protocol, typing.Generic, Literal[object]]