Skip to content

Commit fae22af

Browse files
committed
test for non-object bound; add explicit __init__
1 parent f2c6d32 commit fae22af

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

test-data/unit/check-selftype.test

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,11 @@ reveal_type(x.f) # E: Revealed type is 'builtins.int'
367367

368368
[case testSelfTypeProperSupertypeAttribute]
369369
from typing import Callable, TypeVar
370-
T = TypeVar('T', bound=object)
371-
class A:
370+
class K: pass
371+
T = TypeVar('T', bound=K)
372+
class A(K):
372373
@property
373-
def g(self: object) -> int: return 0
374+
def g(self: K) -> int: return 0
374375
@property
375376
def gt(self: T) -> T: return self
376377
f: Callable[[object], int]
@@ -392,7 +393,7 @@ reveal_type(B().ft()) # E: Revealed type is '__main__.B*'
392393

393394
[case testSelfTypeProperSupertypeAttributeTuple]
394395
from typing import Callable, TypeVar, Tuple
395-
T = TypeVar('T', bound=object)
396+
T = TypeVar('T')
396397
class A(Tuple[int, int]):
397398
@property
398399
def g(self: object) -> int: return 0
@@ -417,7 +418,7 @@ reveal_type(B().ft()) # E: Revealed type is 'Tuple[builtins.int, builtins.int,
417418

418419
[case testSelfTypeProperSupertypeAttributeMeta]
419420
from typing import Callable, TypeVar, Type
420-
T = TypeVar('T', bound=object)
421+
T = TypeVar('T')
421422
class A(type):
422423
@property
423424
def g(cls: object) -> int: return 0
@@ -429,17 +430,18 @@ class A(type):
429430
class B(A):
430431
pass
431432

432-
class X(metaclass=B): pass
433+
class X(metaclass=B):
434+
def __init__(self, x: int) -> None: pass
433435
class Y(X): pass
434436
X1: Type[X]
435437
reveal_type(X.g) # E: Revealed type is 'builtins.int'
436-
reveal_type(X.gt) # E: Revealed type is 'def () -> __main__.X'
438+
reveal_type(X.gt) # E: Revealed type is 'def (x: builtins.int) -> __main__.X'
437439
reveal_type(X.f()) # E: Revealed type is 'builtins.int'
438-
reveal_type(X.ft()) # E: Revealed type is 'def () -> __main__.X'
440+
reveal_type(X.ft()) # E: Revealed type is 'def (x: builtins.int) -> __main__.X'
439441
reveal_type(Y.g) # E: Revealed type is 'builtins.int'
440-
reveal_type(Y.gt) # E: Revealed type is 'def () -> __main__.Y'
442+
reveal_type(Y.gt) # E: Revealed type is 'def (x: builtins.int) -> __main__.Y'
441443
reveal_type(Y.f()) # E: Revealed type is 'builtins.int'
442-
reveal_type(Y.ft()) # E: Revealed type is 'def () -> __main__.Y'
444+
reveal_type(Y.ft()) # E: Revealed type is 'def (x: builtins.int) -> __main__.Y'
443445
reveal_type(X1.g) # E: Revealed type is 'builtins.int'
444446
reveal_type(X1.gt) # E: Revealed type is 'Type[__main__.X]'
445447
reveal_type(X1.f()) # E: Revealed type is 'builtins.int'

0 commit comments

Comments
 (0)