Skip to content

Commit a989775

Browse files
committed
add test for generic instantiation
1 parent fae22af commit a989775

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test-data/unit/check-selftype.test

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,35 @@ reveal_type(X1.ft()) # E: Revealed type is 'Type[__main__.X]'
449449

450450
[builtins fixtures/property.pyi]
451451

452+
[case testSelfTypeProperSupertypeAttributeGeneric]
453+
from typing import Callable, TypeVar, Generic
454+
Q = TypeVar('Q', covariant=True)
455+
class K(Generic[Q]):
456+
q: Q
457+
T = TypeVar('T')
458+
class A(K[Q]):
459+
@property
460+
def g(self: K[object]) -> int: return 0
461+
@property
462+
def gt(self: K[T]) -> T: return self.q
463+
f: Callable[[object], int]
464+
ft: Callable[[T], T]
465+
466+
class B(A[Q]):
467+
pass
468+
a: A[int]
469+
b: B[str]
470+
reveal_type(a.g) # E: Revealed type is 'builtins.int'
471+
--reveal_type(a.gt) # E: Revealed type is 'builtins.int'
472+
reveal_type(a.f()) # E: Revealed type is 'builtins.int'
473+
--reveal_type(a.ft()) # E: Revealed type is '__main__.A*[builtins.int]'
474+
reveal_type(b.g) # E: Revealed type is 'builtins.int'
475+
--reveal_type(b.gt) # E: Revealed type is '__main__.B*[builtins.str]'
476+
reveal_type(b.f()) # E: Revealed type is 'builtins.int'
477+
--reveal_type(b.ft()) # E: Revealed type is '__main__.B*[builtins.str]'
478+
479+
[builtins fixtures/property.pyi]
480+
452481
[case testSelfTypeNotSelfType]
453482
# Friendlier error messages for common mistakes. See #2950
454483
class A:

0 commit comments

Comments
 (0)