[Python-Dev] Possible patch for functools partial - Interested?

Yaniv Aknin yaniv at aknin.name
Thu May 13 10:50:02 CEST 2010


I'm never certain where to reply in such a case, on the list or on the
issue, but since no one is nosy yet to Daniel's patch, I thought I'd ask
here.

While a partial object should reasonably never change, you could change it:
>>> from functools import partial
>>> p = partial(lambda *a, **kw: kw, 1, 2, spam='eggs')
>>> p()
{'spam': 'eggs'}
>>> p.keywords['spam'] = 'bacon'
>>> p()
{'spam': 'bacon'}
>>>

I realize touching p.keywords voids your warranty, but if we can stop people
from doing it, maybe we should (or at least put a warning in the
documentation, no?). So I'm thinking either we make an immutable/hashable
dict while we're at it, or store the keyword arguments as a tuple (which
guarantees immutability), and only convert them back to a dict when you want
to call the partial object (simpler, slower).

Your thoughts? Should we continue this discussion at issue8699?

 - Yaniv

On Thu, May 13, 2010 at 1:11 AM, Daniel Urban <urban.dani at gmail.com> wrote:

> On Fri, May 7, 2010 at 17:02, Antoine Pitrou <solipsis at pitrou.net> wrote:
> > It would be more useful to provide equality, hashing and repr to partial
> itself,
> > rather than a subclass. Feel free to propose a patch :)
>
> Hi!
>
> I've done that.
> I've opened a feature request: http://bugs.python.org/issue8699
> The patch is also at Rietveld: http://codereview.appspot.com/1179044
>
> I'm a beginner, so my patch is probably far from perfect, but I'd
> appreciate any help, and will try to correct my mistakes.
>
> Thanks,
> Daniel Urban
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/yaniv%40aknin.name
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20100513/f1ec8640/attachment.html>


More information about the Python-Dev mailing list