-
-
Notifications
You must be signed in to change notification settings - Fork 148
Fix partial mypy plugin: make positionals keyword-only after a keyword-bound positional (#2191) #2446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix partial mypy plugin: make positionals keyword-only after a keyword-bound positional (#2191) #2446
Changes from all commits
ee8f7d3
a31ef11
72787b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,92 @@ | |
| reveal_type(partial(two_args, second=1.0)) # N: Revealed type is "def (first: int) -> str" | ||
|
|
||
|
|
||
| - case: partial_last_arg_by_keyword_keeps_first_positional | ||
| disable_cache: false | ||
| main: | | ||
| from returns.curry import partial | ||
|
|
||
| def two_args(first: int, second: float) -> str: | ||
| ... | ||
|
|
||
| # `second` is the last parameter, so binding it by keyword leaves no | ||
| # positional parameter after the hole and `first` stays positional: | ||
| reveal_type(partial(two_args, second=2)) # N: Revealed type is "def (first: int) -> str" | ||
|
|
||
|
|
||
| - case: partial_positional_arg_by_keyword_makes_rest_kwonly | ||
| disable_cache: false | ||
| main: | | ||
| from returns.curry import partial | ||
|
|
||
| def two_args(first: int, second: float) -> str: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please, test the same with |
||
| ... | ||
|
|
||
| # `first` is a positional argument bound by keyword, so `second` | ||
| # can no longer be passed positionally at runtime and must be | ||
| # reported as keyword-only: | ||
| reveal_type(partial(two_args, first=1)) # N: Revealed type is "def (*, second: float) -> str" | ||
|
|
||
|
|
||
| - case: partial_keyword_only_arg_stays_keyword_only | ||
| disable_cache: false | ||
| main: | | ||
| from returns.curry import partial | ||
|
|
||
| def two_args(first: int, *, second: float) -> str: | ||
| ... | ||
|
|
||
| # `second` is already keyword-only, so binding the positional `first` | ||
| # by keyword leaves it keyword-only just as before: | ||
| reveal_type(partial(two_args, first=1)) # N: Revealed type is "def (*, second: float) -> str" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, also add |
||
|
|
||
|
|
||
| - case: partial_positional_arg_by_keyword_rejects_positional_call | ||
| disable_cache: false | ||
| main: | | ||
| from returns.curry import partial | ||
|
|
||
| def two_args(first: int, second: float) -> str: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, also add a test case with |
||
| ... | ||
|
|
||
| bound = partial(two_args, first=1) | ||
| bound(second=2.0) # ok | ||
| bound(2.0) # E: Too many positional arguments [misc] | ||
|
|
||
|
|
||
| - case: partial_middle_positional_arg_by_keyword_makes_rest_kwonly | ||
| disable_cache: false | ||
| main: | | ||
| from returns.curry import partial | ||
|
|
||
| def multiple( | ||
| first: int, | ||
| second: float, | ||
| third: str, | ||
| fourth: bool, | ||
| ) -> str: | ||
| ... | ||
|
|
||
| # `second` is bound by keyword, so every positional argument after | ||
| # it (`third`, `fourth`) becomes keyword-only, while `first` which | ||
| # comes before the hole is still reachable positionally: | ||
| reveal_type(partial(multiple, second=0.5)) # N: Revealed type is "def (first: int, *, third: str, fourth: bool) -> str" | ||
|
|
||
|
|
||
| - case: partial_positional_only_before_keyword_bound_arg | ||
| disable_cache: false | ||
| main: | | ||
| from returns.curry import partial | ||
|
|
||
| def multiple(first: int, /, second: int, third: str) -> str: | ||
| ... | ||
|
|
||
| # `second` is bound by keyword, so `third` after the hole becomes | ||
| # keyword-only, while the positional-only `first` before the hole | ||
| # stays positional-only (rendered by mypy without a name): | ||
| reveal_type(partial(multiple, second=1)) # N: Revealed type is "def (int, *, third: str) -> str" | ||
|
|
||
|
|
||
| - case: partial_multiple_args | ||
| disable_cache: false | ||
| main: | | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go under new
## WIPsection, 0.28.0 was already released.