@@ -439,13 +439,16 @@ def f(x: int) -> None: pass
439
439
def g(x: int, y: str) -> None: pass
440
440
441
441
reveal_type(register(lambda: f(1))) # N: Revealed type is "def ()"
442
- reveal_type(register(lambda x: f(x), x=1)) # N: Revealed type is "def (x: Literal[1]?)"
442
+ reveal_type(register(lambda x: f(x), x=1)) # N: Revealed type is "def (*, x: Literal[1]?)" \
443
+ # E: Cannot infer type of lambda
443
444
register(lambda x: f(x)) # E: Cannot infer type of lambda \
444
445
# E: Argument 1 to "register" has incompatible type "Callable[[Any], None]"; expected "Callable[[], None]"
445
- register(lambda x: f(x), y=1) # E: Argument 1 to "register" has incompatible type "Callable[[Arg(int, 'x')], None]"; expected "Callable[[Arg(int, 'y')], None]"
446
+ register(lambda x: f(x), y=1) # E: Cannot infer type of lambda \
447
+ # E: Argument 1 to "register" has incompatible type "Callable[[Any], None]"; expected "Callable[[NamedArg(int, 'y')], None]"
446
448
reveal_type(register(lambda x: f(x), 1)) # N: Revealed type is "def (Literal[1]?)"
447
449
reveal_type(register(lambda x, y: g(x, y), 1, "a")) # N: Revealed type is "def (Literal[1]?, Literal['a']?)"
448
- reveal_type(register(lambda x, y: g(x, y), 1, y="a")) # N: Revealed type is "def (Literal[1]?, y: Literal['a']?)"
450
+ reveal_type(register(lambda x, y: g(x, y), 1, y="a")) # N: Revealed type is "def (Literal[1]?, *, y: Literal['a']?)" \
451
+ # E: Cannot infer type of lambda
449
452
[builtins fixtures/dict.pyi]
450
453
451
454
[case testParamSpecInvalidCalls]
@@ -1677,7 +1680,7 @@ class Foo(Generic[P]):
1677
1680
def test(*args: P.args, **kwargs: P.kwargs) -> Foo[P]: ...
1678
1681
1679
1682
reveal_type(test(1, 2)) # N: Revealed type is "__main__.Foo[[Literal[1]?, Literal[2]?]]"
1680
- reveal_type(test(x=1, y=2)) # N: Revealed type is "__main__.Foo[[x: Literal[1]?, y: Literal[2]?]]"
1683
+ reveal_type(test(x=1, y=2)) # N: Revealed type is "__main__.Foo[[*, x: Literal[1]?, y: Literal[2]?]]"
1681
1684
ints = [1, 2, 3]
1682
1685
reveal_type(test(*ints)) # N: Revealed type is "__main__.Foo[[*builtins.int]]"
1683
1686
[builtins fixtures/paramspec.pyi]
@@ -1732,7 +1735,7 @@ apply(apply, test2, 42, "yes")
1732
1735
apply(apply, test2, "no", 42) # E: Argument 1 to "apply" has incompatible type "Callable[[Callable[P, T], **P], None]"; expected "Callable[[Callable[[int, str], None], str, int], None]"
1733
1736
apply(apply, test2, x=42, y="yes")
1734
1737
apply(apply, test2, y="yes", x=42)
1735
- apply(apply, test2, y=42, x="no") # E: Argument 1 to "apply" has incompatible type "Callable[[Callable[P, T], **P], None]"; expected "Callable[[Callable[[int, str], None], int, str], None]"
1738
+ apply(apply, test2, y=42, x="no") # E: Argument 1 to "apply" has incompatible type "Callable[[Callable[P, T], **P], None]"; expected "Callable[[Callable[[int, str], None], NamedArg( int, 'y'), NamedArg( str, 'x') ], None]"
1736
1739
[builtins fixtures/paramspec.pyi]
1737
1740
1738
1741
[case testParamSpecApplyPosVsNamedOptional]
@@ -2157,7 +2160,7 @@ reveal_type(submit( # N: Revealed type is "__main__.Result"
2157
2160
backend="asyncio",
2158
2161
))
2159
2162
submit(
2160
- run, # E: Argument 1 to "submit" has incompatible type "Callable[[Callable[[], R], VarArg(object), DefaultNamedArg(str, 'backend')], R]"; expected "Callable[[Callable[[], Result], int], Result]"
2163
+ run, # E: Argument 1 to "submit" has incompatible type "Callable[[Callable[[], R], VarArg(object), DefaultNamedArg(str, 'backend')], R]"; expected "Callable[[Callable[[], Result], NamedArg( int, 'backend') ], Result]"
2161
2164
run_portal,
2162
2165
backend=int(),
2163
2166
)
@@ -2532,3 +2535,21 @@ class GenericWrapper(Generic[P]):
2532
2535
def contains(c: Callable[P, None], *args: P.args, **kwargs: P.kwargs) -> None: ...
2533
2536
def inherits(*args: P.args, **kwargs: P.kwargs) -> None: ...
2534
2537
[builtins fixtures/paramspec.pyi]
2538
+
2539
+ [case testParamSpecInferenceFromArgs]
2540
+ from typing_extensions import ParamSpec
2541
+ from typing import Any, Callable, Union
2542
+
2543
+ P = ParamSpec("P")
2544
+
2545
+ def into(f: Callable[P, None], *args: P.args, **kwargs: P.kwargs) -> None:
2546
+ return None
2547
+
2548
+ class C:
2549
+ def f(self, y: bool = False, *, x: int = 42) -> None:
2550
+ return None
2551
+
2552
+ ex: Union[C, Any] = C()
2553
+
2554
+ into(ex.f, x=-1)
2555
+ [builtins fixtures/paramspec.pyi]
0 commit comments