@@ -2560,3 +2560,46 @@ def fn(f: MiddlewareFactory[P]) -> Capture[P]: ...
2560
2560
2561
2561
reveal_type(fn(ServerErrorMiddleware)) # N: Revealed type is "__main__.Capture[[handler: Union[builtins.str, None] =, debug: builtins.bool =]]"
2562
2562
[builtins fixtures/paramspec.pyi]
2563
+
2564
+ [case testRunParamSpecDuplicateArgsKwargs]
2565
+ from typing_extensions import ParamSpec, Concatenate
2566
+ from typing import Callable, Union
2567
+
2568
+ _P = ParamSpec("_P")
2569
+
2570
+ def run(predicate: Callable[_P, None], *args: _P.args, **kwargs: _P.kwargs) -> None:
2571
+ predicate(*args, *args, **kwargs) # E: ParamSpec.args should only be passed once
2572
+ predicate(*args, **kwargs, **kwargs) # E: ParamSpec.kwargs should only be passed once
2573
+ predicate(*args, *args, **kwargs, **kwargs) # E: ParamSpec.args should only be passed once \
2574
+ # E: ParamSpec.kwargs should only be passed once
2575
+ copy_args = args
2576
+ copy_kwargs = kwargs
2577
+ predicate(*args, *copy_args, **kwargs) # E: ParamSpec.args should only be passed once
2578
+ predicate(*copy_args, *args, **kwargs) # E: ParamSpec.args should only be passed once
2579
+ predicate(*args, **copy_kwargs, **kwargs) # E: ParamSpec.kwargs should only be passed once
2580
+ predicate(*args, **kwargs, **copy_kwargs) # E: ParamSpec.kwargs should only be passed once
2581
+
2582
+ def run2(predicate: Callable[Concatenate[int, _P], None], *args: _P.args, **kwargs: _P.kwargs) -> None:
2583
+ predicate(*args, *args, **kwargs) # E: ParamSpec.args should only be passed once \
2584
+ # E: Argument 1 has incompatible type "*_P.args"; expected "int"
2585
+ predicate(*args, **kwargs, **kwargs) # E: ParamSpec.kwargs should only be passed once \
2586
+ # E: Argument 1 has incompatible type "*_P.args"; expected "int"
2587
+ predicate(1, *args, *args, **kwargs) # E: ParamSpec.args should only be passed once
2588
+ predicate(1, *args, **kwargs, **kwargs) # E: ParamSpec.kwargs should only be passed once
2589
+ predicate(1, *args, *args, **kwargs, **kwargs) # E: ParamSpec.args should only be passed once \
2590
+ # E: ParamSpec.kwargs should only be passed once
2591
+ copy_args = args
2592
+ copy_kwargs = kwargs
2593
+ predicate(1, *args, *copy_args, **kwargs) # E: ParamSpec.args should only be passed once
2594
+ predicate(1, *copy_args, *args, **kwargs) # E: ParamSpec.args should only be passed once
2595
+ predicate(1, *args, **copy_kwargs, **kwargs) # E: ParamSpec.kwargs should only be passed once
2596
+ predicate(1, *args, **kwargs, **copy_kwargs) # E: ParamSpec.kwargs should only be passed once
2597
+
2598
+ def run3(predicate: Callable[Concatenate[int, str, _P], None], *args: _P.args, **kwargs: _P.kwargs) -> None:
2599
+ base_ok: tuple[int, str]
2600
+ predicate(*base_ok, *args, **kwargs)
2601
+ base_bad: tuple[Union[int, str], ...]
2602
+ predicate(*base_bad, *args, **kwargs) # E: Argument 1 has incompatible type "*Tuple[Union[int, str], ...]"; expected "int" \
2603
+ # E: Argument 1 has incompatible type "*Tuple[Union[int, str], ...]"; expected "str" \
2604
+ # E: Argument 1 has incompatible type "*Tuple[Union[int, str], ...]"; expected "_P.args"
2605
+ [builtins fixtures/paramspec.pyi]
0 commit comments