Issue27840
Created on 2016-08-23 14:34 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| partial_call_kwargs.patch | vstinner, 2016-08-23 14:34 | review | ||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 253 | vstinner, 2017-02-23 15:40 | ||
| Messages (6) | |||
|---|---|---|---|
| msg273456 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2016-08-23 14:34 | |
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? |
|||
| msg273592 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2016-08-24 20:36 | |
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
|
|||
| msg273691 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2016-08-26 03:27 | |
I concur with Antoine. |
|||
| msg273697 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2016-08-26 09:36 | |
Ah yes sorry, I misunderstood the link between kwargs from a C function and a PY function. The link is simple, it's the same object :-) This issue can be closed. |
|||
| msg288454 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2017-02-23 15:40 | |
I reopen the issue to propose to add a comment explaining why the dictionary must always be copied: https://github.com/python/cpython/pull/253 |
|||
| msg288639 - (view) | Author: Berker Peksag (berker.peksag) * ![]() |
Date: 2017-02-27 12:36 | |
PR 253 has been merged. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:35 | admin | set | github: 72027 |
| 2017-02-27 12:36:56 | berker.peksag | set | status: open -> closed nosy:
+ berker.peksag resolution: rejected |
| 2017-02-23 15:40:30 | vstinner | set | status: closed -> open resolution: rejected -> (no value) messages: + msg288454 pull_requests: + pull_request221 |
| 2016-08-26 13:31:38 | ned.deily | set | status: open -> closed resolution: rejected stage: resolved |
| 2016-08-26 09:36:20 | vstinner | set | messages: + msg273697 |
| 2016-08-26 03:27:51 | rhettinger | set | messages: + msg273691 |
| 2016-08-24 20:36:25 | pitrou | set | nosy:
+ pitrou messages: + msg273592 |
| 2016-08-23 14:34:03 | vstinner | create | |
