@@ -7745,6 +7745,74 @@ class Foo:
77457745 def bad(): # E: Method must have at least one argument. Did you forget the "self" argument?
77467746 self.x = 0 # E: Name "self" is not defined
77477747
7748+ [case testMethodSelfArgumentChecks]
7749+ from typing import Callable, ParamSpec, TypeVar
7750+
7751+ T = TypeVar("T")
7752+ P = ParamSpec("P")
7753+
7754+ def to_number_1(fn: Callable[[], int]) -> int:
7755+ return 0
7756+
7757+ def to_number_2(fn: Callable[[int], int]) -> int:
7758+ return 0
7759+
7760+ def to_same_callable(fn: Callable[P, T]) -> Callable[P, T]:
7761+ return fn
7762+
7763+ class A:
7764+ def undecorated() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument?
7765+
7766+ def undecorated_not_self(x: int) -> None: ... # E: Self argument missing for a non-static method (or an invalid type for self)
7767+
7768+ def undecorated_not_self_2(self: int) -> None: ... # E: The erased type of self "builtins.int" is not a supertype of its class "__main__.A"
7769+
7770+ @to_number_1
7771+ def fn1() -> int:
7772+ return 0
7773+
7774+ @to_number_1 # E: Argument 1 to "to_number_1" has incompatible type "Callable[[int], int]"; expected "Callable[[], int]"
7775+ def fn2(_x: int) -> int:
7776+ return 0
7777+
7778+ @to_number_2 # E: Argument 1 to "to_number_2" has incompatible type "Callable[[], int]"; expected "Callable[[int], int]"
7779+ def fn3() -> int:
7780+ return 0
7781+
7782+ @to_number_2
7783+ def fn4(_x: int) -> int:
7784+ return 0
7785+
7786+ @to_number_2 # E: Argument 1 to "to_number_2" has incompatible type "Callable[[str], int]"; expected "Callable[[int], int]"
7787+ def fn5(_x: str) -> int:
7788+ return 0
7789+
7790+ @to_same_callable
7791+ def g1() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument?
7792+
7793+ @to_same_callable
7794+ def g2(x: int) -> None: ... # E: Self argument missing for a non-static method (or an invalid type for self)
7795+
7796+ @to_same_callable
7797+ def g3(self: int) -> None: ... # E: The erased type of self "builtins.int" is not a supertype of its class "__main__.A"
7798+
7799+ reveal_type(A().fn1) # N: Revealed type is "builtins.int"
7800+ reveal_type(A().fn2) # N: Revealed type is "builtins.int"
7801+ reveal_type(A().fn3) # N: Revealed type is "builtins.int"
7802+ reveal_type(A().fn4) # N: Revealed type is "builtins.int"
7803+ reveal_type(A().fn5) # N: Revealed type is "builtins.int"
7804+
7805+ reveal_type(A().g1) # E: Attribute function "g1" with type "Callable[[], None]" does not accept self argument \
7806+ # N: Revealed type is "def ()"
7807+ reveal_type(A().g2) # E: Invalid self argument "A" to attribute function "g2" with type "Callable[[int], None]" \
7808+ # N: Revealed type is "def ()"
7809+ reveal_type(A().g3) # E: Invalid self argument "A" to attribute function "g3" with type "Callable[[int], None]" \
7810+ # N: Revealed type is "def ()"
7811+
7812+
7813+
7814+ [builtins fixtures/tuple.pyi]
7815+
77487816[case testTypeAfterAttributeAccessWithDisallowAnyExpr]
77497817# flags: --disallow-any-expr
77507818
0 commit comments