Skip to content

Commit 39f2f19

Browse files
author
theodoreando
committed
fix check-protocols and check-functools
1 parent 3ca38fe commit 39f2f19

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

test-data/unit/check-functools.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def takes_callable_int(f: Callable[..., int]) -> None: ...
162162
def takes_callable_str(f: Callable[..., str]) -> None: ...
163163
takes_callable_int(p1)
164164
takes_callable_str(p1) # E: Argument 1 to "takes_callable_str" has incompatible type "partial[int]"; expected "Callable[..., str]" \
165-
# N: "partial[int].__call__" has type "Callable[[VarArg(Any), KwArg(Any)], int]"
165+
# N: "partial[int].__call__" has type "def __call__(__self, *args: Any, **kwargs: Any) -> int"
166166

167167
p2 = functools.partial(foo, 1)
168168
p2("a") # OK
@@ -386,7 +386,7 @@ q: partial[bool] = partial(generic, resulting_type=str) # E: Argument "resultin
386386

387387
pc: Callable[..., str] = partial(generic, resulting_type=str)
388388
qc: Callable[..., bool] = partial(generic, resulting_type=str) # E: Incompatible types in assignment (expression has type "partial[str]", variable has type "Callable[..., bool]") \
389-
# N: "partial[str].__call__" has type "Callable[[VarArg(Any), KwArg(Any)], str]"
389+
# N: "partial[str].__call__" has type "def __call__(__self, *args: Any, **kwargs: Any) -> str"
390390
[builtins fixtures/tuple.pyi]
391391

392392
[case testFunctoolsPartialNestedPartial]
@@ -697,11 +697,11 @@ use_int_callable(partial(func_b, b=""))
697697
use_func_callable(partial(func_b, b=""))
698698
use_int_callable(partial(func_c, b=""))
699699
use_func_callable(partial(func_c, b=""))
700-
use_int_callable(partial(func_fn, b="")) # E: Argument 1 to "use_int_callable" has incompatible type "partial[Callable[[VarArg(Any), KwArg(Any)], Any]]"; expected "Callable[[int], int]" \
701-
# N: "partial[Callable[[VarArg(Any), KwArg(Any)], Any]].__call__" has type "Callable[[VarArg(Any), KwArg(Any)], Callable[[VarArg(Any), KwArg(Any)], Any]]"
700+
use_int_callable(partial(func_fn, b="")) # E: Argument 1 to "use_int_callable" has incompatible type "partial[def (*Any, **Any) -> Any]"; expected "Callable[[int], int]" \
701+
# N: "partial[Callable[[VarArg(Any), KwArg(Any)], Any]].__call__" has type "def __call__(__self, *args: Any, **kwargs: Any) -> def (*Any, **Any) -> Any"
702702
use_func_callable(partial(func_fn, b=""))
703-
use_int_callable(partial(func_fn_unpack, b="")) # E: Argument 1 to "use_int_callable" has incompatible type "partial[Callable[[VarArg(Any)], Any]]"; expected "Callable[[int], int]" \
704-
# N: "partial[Callable[[VarArg(Any)], Any]].__call__" has type "Callable[[VarArg(Any), KwArg(Any)], Callable[[VarArg(Any)], Any]]"
703+
use_int_callable(partial(func_fn_unpack, b="")) # E: Argument 1 to "use_int_callable" has incompatible type "partial[def (*Any) -> Any]"; expected "Callable[[int], int]" \
704+
# N: "partial[Callable[[VarArg(Any)], Any]].__call__" has type "def __call__(__self, *args: Any, **kwargs: Any) -> def (*Any) -> Any"
705705
use_func_callable(partial(func_fn_unpack, b=""))
706706

707707
# But we should not erase typevars that aren't bound by function
@@ -714,7 +714,7 @@ def outer_b(arg: Tb) -> None:
714714

715715
reveal_type(partial(inner, b="")) # N: Revealed type is "functools.partial[Tb`-1]"
716716
use_int_callable(partial(inner, b="")) # E: Argument 1 to "use_int_callable" has incompatible type "partial[Tb]"; expected "Callable[[int], int]" \
717-
# N: "partial[Tb].__call__" has type "Callable[[VarArg(Any), KwArg(Any)], Tb]"
717+
# N: "partial[Tb].__call__" has type "def __call__(__self, *args: Any, **kwargs: Any) -> Tb"
718718

719719
def outer_c(arg: Tc) -> None:
720720

@@ -724,5 +724,5 @@ def outer_c(arg: Tc) -> None:
724724
reveal_type(partial(inner, b="")) # N: Revealed type is "functools.partial[builtins.int]" \
725725
# N: Revealed type is "functools.partial[builtins.str]"
726726
use_int_callable(partial(inner, b="")) # E: Argument 1 to "use_int_callable" has incompatible type "partial[str]"; expected "Callable[[int], int]" \
727-
# N: "partial[str].__call__" has type "Callable[[VarArg(Any), KwArg(Any)], str]"
727+
# N: "partial[str].__call__" has type "def __call__(__self, *args: Any, **kwargs: Any) -> str"
728728
[builtins fixtures/tuple.pyi]

test-data/unit/check-protocols.test

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ reveal_type(apply_gen(Add5())) # N: Revealed type is "builtins.int"
18941894
def apply_str(f: Callable[[str], int], x: str) -> int:
18951895
return f(x)
18961896
apply_str(Add5(), 'a') # E: Argument 1 to "apply_str" has incompatible type "Add5"; expected "Callable[[str], int]" \
1897-
# N: "Add5.__call__" has type "Callable[[Arg(int, 'x')], int]"
1897+
# N: "Add5.__call__" has type "def __call__(self, x: int) -> int"
18981898
[builtins fixtures/isinstancelist.pyi]
18991899

19001900
[case testMoreComplexCallableStructuralSubtyping]
@@ -1910,10 +1910,10 @@ class Bad1:
19101910
class Bad2:
19111911
def __call__(self, y: int, *rest: str) -> int: pass
19121912
call_soon(Good())
1913-
call_soon(Bad1()) # E: Argument 1 to "call_soon" has incompatible type "Bad1"; expected "Callable[[int, VarArg(str)], int]" \
1914-
# N: "Bad1.__call__" has type "Callable[[Arg(int, 'x'), VarArg(int)], int]"
1915-
call_soon(Bad2()) # E: Argument 1 to "call_soon" has incompatible type "Bad2"; expected "Callable[[int, VarArg(str)], int]" \
1916-
# N: "Bad2.__call__" has type "Callable[[Arg(int, 'y'), VarArg(str)], int]"
1913+
call_soon(Bad1()) # E: Argument 1 to "call_soon" has incompatible type "Bad1"; expected "def (x: int, *str) -> int" \
1914+
# N: "Bad1.__call__" has type "def __call__(self, x: int, *rest: int) -> int"
1915+
call_soon(Bad2()) # E: Argument 1 to "call_soon" has incompatible type "Bad2"; expected "def (x: int, *str) -> int" \
1916+
# N: "Bad2.__call__" has type "def __call__(self, y: int, *rest: str) -> int"
19171917
[builtins fixtures/isinstancelist.pyi]
19181918

19191919
[case testStructuralSupportForPartial]
@@ -2473,8 +2473,8 @@ def func(caller: Caller) -> None:
24732473
pass
24742474

24752475
func(call)
2476-
func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[int, VarArg(str)], None]"; expected "Caller" \
2477-
# N: "Caller.__call__" has type "Callable[[Arg(str, 'x'), VarArg(int)], None]"
2476+
func(bad) # E: Argument 1 to "func" has incompatible type "def bad(x: int, *args: str) -> None"; expected "Caller" \
2477+
# N: "Caller.__call__" has type "def __call__(self, x: str, *args: int) -> None"
24782478
[builtins fixtures/tuple.pyi]
24792479
[out]
24802480

@@ -2512,7 +2512,7 @@ def func(caller: Caller) -> None:
25122512

25132513
func(call)
25142514
func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[int], int]"; expected "Caller" \
2515-
# N: "Caller.__call__" has type "Callable[[Arg(T, 'x')], T]"
2515+
# N: "Caller.__call__" has type "def [T] __call__(self, x: T) -> T"
25162516
[builtins fixtures/tuple.pyi]
25172517
[out]
25182518

@@ -2533,7 +2533,7 @@ def func(caller: Caller) -> None:
25332533

25342534
func(call)
25352535
func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[T], tuple[T, T]]"; expected "Caller" \
2536-
# N: "Caller.__call__" has type "Callable[[Arg(int, 'x')], int]"
2536+
# N: "Caller.__call__" has type "def __call__(self, x: int) -> int"
25372537
[builtins fixtures/tuple.pyi]
25382538
[out]
25392539

@@ -2573,8 +2573,8 @@ class Caller(Protocol):
25732573
def bad(x: int, *args: str) -> None:
25742574
pass
25752575

2576-
cb: Caller = bad # E: Incompatible types in assignment (expression has type "Callable[[int, VarArg(str)], None]", variable has type "Caller") \
2577-
# N: "Caller.__call__" has type "Callable[[Arg(str, 'x'), VarArg(int)], None]"
2576+
cb: Caller = bad # E: Incompatible types in assignment (expression has type "def bad(x: int, *args: str) -> None", variable has type "Caller") \
2577+
# N: "Caller.__call__" has type "def __call__(self, x: str, *args: int) -> None"
25782578
[builtins fixtures/tuple.pyi]
25792579
[out]
25802580

@@ -2601,7 +2601,7 @@ def anon(caller: CallerAnon) -> None:
26012601

26022602
func(call)
26032603
func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[str], None]"; expected "Caller" \
2604-
# N: "Caller.__call__" has type "Callable[[Arg(str, 'x')], None]"
2604+
# N: "Caller.__call__" has type "def __call__(self, x: str) -> None"
26052605
anon(bad)
26062606
[out]
26072607

@@ -2625,7 +2625,7 @@ b: Bad
26252625

26262626
func(a)
26272627
func(b) # E: Argument 1 to "func" has incompatible type "Bad"; expected "One" \
2628-
# N: "One.__call__" has type "Callable[[Arg(str, 'x')], None]"
2628+
# N: "One.__call__" has type "def __call__(self, x: str) -> None"
26292629
[out]
26302630

26312631
[case testJoinProtocolCallback]
@@ -3597,7 +3597,7 @@ test(C) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P"
35973597
# N: def __call__(x: int, y: int) -> Any \
35983598
# N: Got: \
35993599
# N: def __init__(x: int, y: str) -> C \
3600-
# N: "P.__call__" has type "Callable[[Arg(int, 'x'), Arg(int, 'y')], Any]"
3600+
# N: "P.__call__" has type "def __call__(self, x: int, y: int) -> Any"
36013601

36023602
[case testProtocolClassObjectPureCallback]
36033603
from typing import Any, ClassVar, Protocol
@@ -3619,7 +3619,7 @@ test(C) # E: Argument 1 to "test" has incompatible type "type[C]"; expected "P"
36193619
# N: def __call__(x: int, y: int) -> Any \
36203620
# N: Got: \
36213621
# N: def __init__(x: int, y: str) -> C \
3622-
# N: "P.__call__" has type "Callable[[Arg(int, 'x'), Arg(int, 'y')], Any]"
3622+
# N: "P.__call__" has type "def __call__(self, x: int, y: int) -> Any"
36233623
[builtins fixtures/type.pyi]
36243624

36253625
[case testProtocolClassObjectCallableError]
@@ -3642,7 +3642,7 @@ p: P = C # E: Incompatible types in assignment (expression has type "type[C]",
36423642
# N: def __call__(app: int) -> Callable[[str], None] \
36433643
# N: Got: \
36443644
# N: def __init__(app: str) -> C \
3645-
# N: "P.__call__" has type "Callable[[Arg(int, 'app')], Callable[[str], None]]"
3645+
# N: "P.__call__" has type "def __call__(self, app: int) -> Callable[[str], None]"
36463646

36473647
[builtins fixtures/type.pyi]
36483648

@@ -3801,7 +3801,7 @@ def f_good(t: S) -> S:
38013801
return t
38023802

38033803
g: C = f_bad # E: Incompatible types in assignment (expression has type "Callable[[int], int]", variable has type "C") \
3804-
# N: "C.__call__" has type "Callable[[Arg(T, 't')], T]"
3804+
# N: "C.__call__" has type "def [T] __call__(self, t: T) -> T"
38053805
g = f_good # OK
38063806

38073807
[case testModuleAsProtocolImplementation]

0 commit comments

Comments
 (0)