@@ -588,39 +588,51 @@ A().f('') # E: Argument 1 to "f" of "A" has incompatible type "str"; expected "i
588588
589589
590590[case testMethodAsDataAttribute]
591- from typing import Any, Callable
591+ from typing import Any, Callable, ClassVar
592592class B: pass
593593x = None # type: Any
594594class A:
595- f = x # type: Callable[[A], None]
596- g = x # type: Callable[[A, B], None]
595+ f = x # type: ClassVar[ Callable[[A], None] ]
596+ g = x # type: ClassVar[ Callable[[A, B], None] ]
597597a = None # type: A
598598a.f()
599599a.g(B())
600600a.f(a) # E: Too many arguments
601601a.g() # E: Too few arguments
602602
603603[case testMethodWithInvalidMethodAsDataAttribute]
604- from typing import Any, Callable
604+ from typing import Any, Callable, ClassVar
605605class B: pass
606606x = None # type: Any
607607class A:
608- f = x # type: Callable[[], None]
609- g = x # type: Callable[[B], None]
608+ f = x # type: ClassVar[ Callable[[], None] ]
609+ g = x # type: ClassVar[ Callable[[B], None] ]
610610a = None # type: A
611611a.f() # E: Attribute function "f" with type "Callable[[], None]" does not accept self argument
612612a.g() # E: Invalid self argument "A" to attribute function "g" with type "Callable[[B], None]"
613613
614614[case testMethodWithDynamicallyTypedMethodAsDataAttribute]
615- from typing import Any, Callable
615+ from typing import Any, Callable, ClassVar
616616class B: pass
617617x = None # type: Any
618618class A:
619- f = x # type: Callable[[Any], Any]
619+ f = x # type: ClassVar[ Callable[[Any], Any] ]
620620a = None # type: A
621621a.f()
622622a.f(a) # E: Too many arguments
623623
624+ [case testMethodWithInferredMethodAsDataAttribute]
625+ from typing import Any
626+ def m(self: "A") -> int: ...
627+
628+ class A:
629+ n = m
630+
631+ a = A()
632+ reveal_type(a.n()) # N: Revealed type is "builtins.int"
633+ reveal_type(A.n(a)) # N: Revealed type is "builtins.int"
634+ A.n() # E: Too few arguments
635+
624636[case testOverloadedMethodAsDataAttribute]
625637from foo import *
626638[file foo.pyi]
@@ -662,35 +674,35 @@ a.g(B())
662674a.g(a) # E: Argument 1 has incompatible type "A[B]"; expected "B"
663675
664676[case testInvalidMethodAsDataAttributeInGenericClass]
665- from typing import Any, TypeVar, Generic, Callable
677+ from typing import Any, TypeVar, Generic, Callable, ClassVar
666678t = TypeVar('t')
667679class B: pass
668680class C: pass
669681x = None # type: Any
670682class A(Generic[t]):
671- f = x # type: Callable[[A[B]], None]
683+ f = x # type: ClassVar[ Callable[[A[B]], None] ]
672684ab = None # type: A[B]
673685ac = None # type: A[C]
674686ab.f()
675687ac.f() # E: Invalid self argument "A[C]" to attribute function "f" with type "Callable[[A[B]], None]"
676688
677689[case testPartiallyTypedSelfInMethodDataAttribute]
678- from typing import Any, TypeVar, Generic, Callable
690+ from typing import Any, TypeVar, Generic, Callable, ClassVar
679691t = TypeVar('t')
680692class B: pass
681693class C: pass
682694x = None # type: Any
683695class A(Generic[t]):
684- f = x # type: Callable[[A], None]
696+ f = x # type: ClassVar[ Callable[[A], None] ]
685697ab = None # type: A[B]
686698ac = None # type: A[C]
687699ab.f()
688700ac.f()
689701
690702[case testCallableDataAttribute]
691- from typing import Callable
703+ from typing import Callable, ClassVar
692704class A:
693- g = None # type: Callable[[A], None]
705+ g = None # type: ClassVar[ Callable[[A], None] ]
694706 def __init__(self, f: Callable[[], None]) -> None:
695707 self.f = f
696708a = A(None)
0 commit comments