Commit b20fa1f
Fix false positive unexpected-keyword for named params before *args: P.args
Summary:
Functions like call_with_retry(f, max_attempts=10, *args: P.args, **kwargs: P.kwargs) should allow max_attempts to be passed as a keyword argument, matching mypy and pyright behavior. Pyrefly incorrectly rejected call_with_retry(write_data, max_attempts=5) with "Unexpected keyword argument max_attempts".
The issue is in callable_infer's handling of the Type::Var(var) branch — the path taken when P hasn't been solved yet (e.g. before matching f to write_data resolves P to ()). This branch constructs a param list from prefix params via ParamList::new_types, which calls into_param(). That method unconditionally converts all PrefixParam::Pos to Param::PosOnly, so max_attempts never enters the keyword params map and any keyword usage is rejected.
The fix switches this branch to use to_subset_param(), which preserves the Pos kind. The PosOnly conversion is deliberately kept for the Type::Quantified branch (ParamSpec forwarding), where foo(x=1, *args, **kwargs) must be rejected — passing a prefix param as keyword while also forwarding *args positionally would cause "multiple values for argument" at runtime. The existing test_paramspec_named_arguments_concatenate test validates this distinction.
Fixes #3052
Reviewed By: grievejia
Differential Revision: D99916739
fbshipit-source-id: c2d92232f8ca5399f3c4d34fa2b2e140d75db07f1 parent 5ff9350 commit b20fa1f
3 files changed
Lines changed: 54 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
299 | | - | |
300 | | - | |
301 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | | - | |
| 322 | + | |
| 323 | + | |
323 | 324 | | |
324 | 325 | | |
325 | 326 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1345 | 1345 | | |
1346 | 1346 | | |
1347 | 1347 | | |
| 1348 | + | |
| 1349 | + | |
1348 | 1350 | | |
1349 | 1351 | | |
1350 | | - | |
| 1352 | + | |
1351 | 1353 | | |
1352 | 1354 | | |
1353 | 1355 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
824 | 824 | | |
825 | 825 | | |
826 | 826 | | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
0 commit comments