-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Support ParamSpec mapping with functools.partial #17355
Support ParamSpec mapping with functools.partial #17355
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 |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]
|
Follow-up for #17323, resolving a false positive discovered there.
Closes #17960.
This enables use of
functools.partial
to bind some*args
or**kwargs
on a callable typed withParamSpec
.