@@ -128,6 +128,57 @@ reveal_type(cast(A, C()).copy()) # N: Revealed type is "__main__.A"
128128
129129[builtins fixtures/bool.pyi]
130130
131+ [case testSelfTypeOverrideCompatibility]
132+ from typing import overload, TypeVar, Generic
133+
134+ T = TypeVar("T", str, int)
135+
136+ class A(Generic[T]):
137+ @overload
138+ def f(self: A[int]) -> int: ...
139+ @overload
140+ def f(self: A[str]) -> str: ...
141+ def f(self): ...
142+
143+ class B(A[T]):
144+ @overload
145+ def f(self: A[int]) -> int: ...
146+ @overload
147+ def f(self: A[str]) -> str: ...
148+ def f(self): ...
149+
150+ class C(A[int]):
151+ def f(self) -> int: ...
152+
153+ class D(A[str]):
154+ def f(self) -> int: ... # E: Signature of "f" incompatible with supertype "A" \
155+ # N: Superclass: \
156+ # N: @overload \
157+ # N: def f(self) -> str \
158+ # N: Subclass: \
159+ # N: def f(self) -> int
160+
161+ class E(A[T]):
162+ def f(self) -> int: ... # E: Signature of "f" incompatible with supertype "A" \
163+ # N: Superclass: \
164+ # N: @overload \
165+ # N: def f(self) -> int \
166+ # N: @overload \
167+ # N: def f(self) -> str \
168+ # N: Subclass: \
169+ # N: def f(self) -> int
170+
171+
172+ class F(A[bytes]): # E: Value of type variable "T" of "A" cannot be "bytes"
173+ def f(self) -> bytes: ... # E: Signature of "f" incompatible with supertype "A" \
174+ # N: Superclass: \
175+ # N: @overload \
176+ # N: def f(self) -> int \
177+ # N: @overload \
178+ # N: def f(self) -> str \
179+ # N: Subclass: \
180+ # N: def f(self) -> bytes
181+
131182[case testSelfTypeSuper]
132183from typing import TypeVar, cast
133184
0 commit comments