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
functools.partial: don't copy keywoard arguments in partial_call()? #72027
Comments
I justed optimized partial_call() for positional arguments in the change c1a698edfa1b to avoid the creation of a temporary tuple when possible. I noticed that keyword parameters from partial() constructor are always copied. Is it mandatory? Can't we avoid copying them? Example: import functools
hello = functools.partial(print, "Hello World", end='!\n')
hello() hello keyword arguments are {'end'; '!\n'}. Attached patch avoids copying keyword arguments when the partial objects is not called with new keyword arguments. Tests pass, but I don't know if there is a risk that some strange function modify keyword arguments in-place? |
Modifying the keyword arguments dict is quite common so this change would be a heavy compatibility breaker. A well-known idiom: def some_function(..., **kwargs):
some_option = kwargs.pop('some_option', None)
# further process kwargs |
I concur with Antoine. |
Ah yes sorry, I misunderstood the link between kwargs from a C function and |
I reopen the issue to propose to add a comment explaining why the dictionary must always be copied: |
PR 253 has been merged. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: