[New-bugs-announce] [issue27840] functools.partial: don't copy keywoard arguments in partial_call()?

STINNER Victor report at bugs.python.org
Tue Aug 23 10:34:03 EDT 2016


New submission from STINNER Victor:

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?

----------
files: partial_call_kwargs.patch
keywords: patch
messages: 273456
nosy: haypo, rhettinger, serhiy.storchaka
priority: normal
severity: normal
status: open
title: functools.partial: don't copy keywoard arguments in partial_call()?
type: performance
versions: Python 3.6
Added file: http://bugs.python.org/file44199/partial_call_kwargs.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27840>
_______________________________________


More information about the New-bugs-announce mailing list