@@ -7808,9 +7808,107 @@ reveal_type(A().g2) # E: Invalid self argument "A" to attribute function "g2" w
78087808 # N: Revealed type is "def ()"
78097809reveal_type(A().g3) # E: Invalid self argument "A" to attribute function "g3" with type "Callable[[int], None]" \
78107810 # N: Revealed type is "def ()"
7811+ [builtins fixtures/tuple.pyi]
7812+
7813+ [case testMethodSelfArgumentChecksConcatenate]
7814+ from typing import Callable, ParamSpec, TypeVar
7815+ from typing_extensions import Concatenate
7816+
7817+ T = TypeVar("T")
7818+ P = ParamSpec("P")
7819+ R = TypeVar("R")
7820+
7821+ def to_same_callable(fn: Callable[Concatenate[T, P], R]) -> Callable[Concatenate[T, P], R]:
7822+ return fn
7823+
7824+ def remove_first(fn: Callable[Concatenate[T, P], R]) -> Callable[P, R]:
7825+ ...
7826+
7827+ def add_correct_first(fn: Callable[P, R]) -> Callable[Concatenate["C", P], R]:
7828+ ...
78117829
7830+ def add_wrong_first(fn: Callable[P, R]) -> Callable[Concatenate[int, P], R]:
7831+ ...
78127832
7833+ class A:
7834+ @to_same_callable # E: Argument 1 to "to_same_callable" has incompatible type "Callable[[], int]"; expected "Callable[[T], int]"
7835+ def fn1() -> int:
7836+ return 0
7837+
7838+ @to_same_callable
7839+ def fn2(_x: int) -> int: # E: Self argument missing for a non-static method (or an invalid type for self)
7840+ return 0
7841+
7842+ @to_same_callable
7843+ def fn3(self, _x: int) -> int:
7844+ return 0
7845+
7846+ reveal_type(A().fn1) # N: Revealed type is "def () -> builtins.int"
7847+ reveal_type(A().fn2) # E: Invalid self argument "A" to attribute function "fn2" with type "Callable[[int], int]" \
7848+ # N: Revealed type is "def () -> builtins.int"
7849+ reveal_type(A().fn3) # N: Revealed type is "def (_x: builtins.int) -> builtins.int"
7850+
7851+ class B:
7852+ @remove_first # E: Argument 1 to "remove_first" has incompatible type "Callable[[], int]"; expected "Callable[[T], int]"
7853+ def fn1() -> int: # E: Method must have at least one argument. Did you forget the "self" argument?
7854+ return 0
7855+
7856+ @remove_first
7857+ def fn2(_x: int) -> int: # E: Method must have at least one argument. Did you forget the "self" argument?
7858+ return 0
7859+
7860+ @remove_first
7861+ def fn3(self, _x: int) -> int: # E: Self argument missing for a non-static method (or an invalid type for self)
7862+ return 0
7863+
7864+ @remove_first
7865+ def fn4(self, new_self: 'B') -> int:
7866+ return 0
7867+
7868+ reveal_type(B().fn1) # E: Attribute function "fn1" with type "Callable[[], int]" does not accept self argument \
7869+ # N: Revealed type is "def () -> builtins.int"
7870+ reveal_type(B().fn2) # E: Attribute function "fn2" with type "Callable[[], int]" does not accept self argument \
7871+ # N: Revealed type is "def () -> builtins.int"
7872+ reveal_type(B().fn3) # E: Invalid self argument "B" to attribute function "fn3" with type "Callable[[int], int]" \
7873+ # N: Revealed type is "def () -> builtins.int"
7874+ reveal_type(B().fn4) # N: Revealed type is "def () -> builtins.int"
7875+
7876+ class C:
7877+ @add_correct_first
7878+ def fn1() -> int:
7879+ return 0
7880+
7881+ @add_correct_first
7882+ def fn2(_x: int) -> int:
7883+ return 0
7884+
7885+ @add_correct_first
7886+ def fn3(self, _x: int) -> int:
7887+ return 0
7888+
7889+ reveal_type(C().fn1) # N: Revealed type is "def () -> builtins.int"
7890+ reveal_type(C().fn2) # N: Revealed type is "def (_x: builtins.int) -> builtins.int"
7891+ reveal_type(C().fn3) # N: Revealed type is "def (self: __main__.C, _x: builtins.int) -> builtins.int"
7892+
7893+ class D:
7894+ @add_wrong_first
7895+ def fn1() -> int: # E: Self argument missing for a non-static method (or an invalid type for self)
7896+ return 0
7897+
7898+ @add_wrong_first
7899+ def fn2(_x: int) -> int: # E: Self argument missing for a non-static method (or an invalid type for self)
7900+ return 0
7901+
7902+ @add_wrong_first
7903+ def fn3(self, _x: int) -> int: # E: Self argument missing for a non-static method (or an invalid type for self)
7904+ return 0
78137905
7906+ reveal_type(D().fn1) # E: Invalid self argument "D" to attribute function "fn1" with type "Callable[[int], int]" \
7907+ # N: Revealed type is "def () -> builtins.int"
7908+ reveal_type(D().fn2) # E: Invalid self argument "D" to attribute function "fn2" with type "Callable[[int, int], int]" \
7909+ # N: Revealed type is "def (_x: builtins.int) -> builtins.int"
7910+ reveal_type(D().fn3) # E: Invalid self argument "D" to attribute function "fn3" with type "Callable[[int, D, int], int]" \
7911+ # N: Revealed type is "def (self: __main__.D, _x: builtins.int) -> builtins.int"
78147912[builtins fixtures/tuple.pyi]
78157913
78167914[case testTypeAfterAttributeAccessWithDisallowAnyExpr]
0 commit comments