[ty] Implement implicit inheritance from Generic[] for PEP-695 generic classes (#18283)

This commit is contained in:
Alex Waygood 2025-05-26 20:40:16 +01:00 committed by GitHub
parent 1d20cf9570
commit 0a11baf29c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 166 additions and 101 deletions

View file

@ -58,9 +58,13 @@ class Bar1(Protocol[T], Generic[T]):
class Bar2[T](Protocol):
x: T
# error: [invalid-generic-class] "Cannot both inherit from subscripted `typing.Protocol` and use PEP 695 type variables"
# error: [invalid-generic-class] "Cannot both inherit from subscripted `Protocol` and use PEP 695 type variables"
class Bar3[T](Protocol[T]):
x: T
# Note that this class definition *will* actually succeed at runtime,
# unlike classes that combine PEP-695 type parameters with inheritance from `Generic[]`
reveal_type(Bar3.__mro__) # revealed: tuple[<class 'Bar3[Unknown]'>, typing.Protocol, typing.Generic, <class 'object'>]
```
It's an error to include both bare `Protocol` and subscripted `Protocol[]` in the bases list