[ty] Ban protocols from inheriting from non-protocol generic classes by AlexWaygood · Pull Request #19941 · astral-sh/ruff (original) (raw)
Summary
This is extracted from #19866, since I need to do some debugging on that PR but this makes sense as a standalone fix.
Currently we correctly emit a diagnostic on this class, which will fail at runtime (a protocol class cannot inherit from a non-protocol class, and int is not a protocol class):
from typing import Protocol
class Foo(int, Protocol): ...
but we don't emit a diagnostic on this class (even though it also fails at runtime):
from typing import Protocol
class Foo(list[int], Protocol): ...
The reason for this is that list[int] is represented in our model as a Type::GenericAlias rather than a Type::ClassLiteral. This PR fixes that oversight.
Test Plan
mdtest added