Support ParamSpec mapping with functools.partial#17355
Support ParamSpec mapping with functools.partial#17355ilevkivskyi merged 21 commits intopython:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ec-with-functools-partial
fd79c7a to
01390c0
Compare
This comment has been minimized.
This comment has been minimized.
|
FWIW I don't like this. |
|
TBH, I tend to agree with @ilevkivskyi - there's a balance between "we want to support this case correctly" and "we don't want to embed too many library-specific details into the typechecker". As far as I see, there's no other way to track such |
…ec-with-functools-partial
This comment has been minimized.
This comment has been minimized.
…ges, but is much less intrusive
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@ilevkivskyi tagging you since you gave some feedback on the first revision. I managed to remove the scary part - error messages are less specific now, but only |
ilevkivskyi
left a comment
There was a problem hiding this comment.
LG, I don't really understand the bound start args logic, but it will be easy to tweak if it will cause problems.
|
|
||
| def run_bad3(func: Callable[Concatenate[int, P], T], *args: P.args, **kwargs: P.kwargs) -> T: | ||
| func2 = partial(func, 1, *args) | ||
| return func2(1, **kwargs) # E: Argument 1 has incompatible type "int"; expected "P.args" |
There was a problem hiding this comment.
The bodies of run_bad2 and run_bad3 look identical. Did you want to test something else here?
There was a problem hiding this comment.
Ough, thanks for spotting! Updated.
…ec-with-functools-partial
This comment has been minimized.
This comment has been minimized.
…ec-with-functools-partial
This comment has been minimized.
This comment has been minimized.
I just invented a counterexample to that test, it's indeed not sufficient to check by arg kinds. Last commit should address that problem and make the logic more clear as well. |
|
Diff from mypy_primer, showing the effect of this PR on open source code: starlette (https://github.com/encode/starlette)
- starlette/concurrency.py:38: error: Too few arguments [call-arg]
|
See issue: python/mypy#17960 Fixed in master: python/mypy#17355 after last release v1.3.0.
See issue: python/mypy#17960 Fixed in master: python/mypy#17355 after last release v1.3.0.
Follow-up for #17323, resolving a false positive discovered there.
Closes #17960.
This enables use of
functools.partialto bind some*argsor**kwargson a callable typed withParamSpec.