@@ -2625,18 +2625,26 @@ T = TypeVar('T', bound=Callable)
2625
2625
def decorator(f: T) -> T:
2626
2626
return f
2627
2627
2628
- a, b = None, None # type: A, B
2628
+ def bad(f: Callable) -> Callable[[int], int]:
2629
+ return f
2630
+
2629
2631
class A:
2630
2632
@decorator
2631
2633
def __getattribute__(self, x: str) -> A:
2632
2634
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()
2634
2639
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")
2637
2647
[builtins fixtures/tuple.pyi]
2638
- [out]
2639
- main:16: error: Incompatible types in assignment (expression has type "A", variable has type "B")
2640
2648
2641
2649
[case testGetattributeSignature]
2642
2650
class A:
@@ -2673,18 +2681,26 @@ T = TypeVar('T', bound=Callable)
2673
2681
def decorator(f: T) -> T:
2674
2682
return f
2675
2683
2676
- a, b = None, None # type: A, B
2684
+ def bad(f: Callable) -> Callable[[int], int]:
2685
+ return f
2686
+
2677
2687
class A:
2678
2688
@decorator
2679
2689
def __getattr__(self, x: str) -> A:
2680
2690
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()
2682
2695
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")
2685
2703
[builtins fixtures/tuple.pyi]
2686
- [out]
2687
- main:16: error: Incompatible types in assignment (expression has type "A", variable has type "B")
2688
2704
2689
2705
[case testGetattrWithGetitem]
2690
2706
class A:
0 commit comments