Skip to content

Commit 28d950d

Browse files
committed
Addresses code review
1 parent b7a2bc9 commit 28d950d

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

test-data/unit/check-classes.test

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,18 +2625,26 @@ T = TypeVar('T', bound=Callable)
26252625
def decorator(f: T) -> T:
26262626
return f
26272627

2628-
a, b = None, None # type: A, B
2628+
def bad(f: Callable) -> Callable[[int], int]:
2629+
return f
2630+
26292631
class A:
26302632
@decorator
26312633
def __getattribute__(self, x: str) -> A:
26322634
return A()
2633-
class B: pass
2635+
class B:
2636+
@bad # We test that type will be take from decorated node, not type
2637+
def __getattribute__(self, x: str) -> A:
2638+
return A()
26342639

2635-
a = a.foo
2636-
b = a.bar
2640+
a: A
2641+
b: B
2642+
2643+
a1: A = a.foo
2644+
b1: B = a.bar # E: Incompatible types in assignment (expression has type "A", variable has type "B")
2645+
a2: A = b.baz
2646+
b2: B = b.roo # E: Incompatible types in assignment (expression has type "A", variable has type "B")
26372647
[builtins fixtures/tuple.pyi]
2638-
[out]
2639-
main:16: error: Incompatible types in assignment (expression has type "A", variable has type "B")
26402648

26412649
[case testGetattributeSignature]
26422650
class A:
@@ -2673,18 +2681,26 @@ T = TypeVar('T', bound=Callable)
26732681
def decorator(f: T) -> T:
26742682
return f
26752683

2676-
a, b = None, None # type: A, B
2684+
def bad(f: Callable) -> Callable[[int], int]:
2685+
return f
2686+
26772687
class A:
26782688
@decorator
26792689
def __getattr__(self, x: str) -> A:
26802690
return A()
2681-
class B: pass
2691+
class B:
2692+
@bad # We test that type will be take from decorated node, not type
2693+
def __getattr__(self, x: str) -> A:
2694+
return A()
26822695

2683-
a = a.foo
2684-
b = a.bar
2696+
a: A
2697+
b: B
2698+
2699+
a1: A = a.foo
2700+
b1: B = a.bar # E: Incompatible types in assignment (expression has type "A", variable has type "B")
2701+
a2: A = b.baz
2702+
b2: B = b.roo # E: Incompatible types in assignment (expression has type "A", variable has type "B")
26852703
[builtins fixtures/tuple.pyi]
2686-
[out]
2687-
main:16: error: Incompatible types in assignment (expression has type "A", variable has type "B")
26882704

26892705
[case testGetattrWithGetitem]
26902706
class A:

0 commit comments

Comments
 (0)