This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Alexander.Belopolsky
Recipients Alexander.Belopolsky
Date 2010-02-01.19:07:27
SpamBayes Score 3.4242553e-11
Marked as misclassified No
Message-id <1265051251.66.0.305258896073.issue7830@psf.upfronthosting.co.za>
In-reply-to
Content
Currently applying functools.partial to a callable that is already functools.partial object results in a nested object:

>>> from functools import partial
>>> def f(a,b,c): pass
... 
>>> p = partial(partial(f, 1), 2)
>>> p.func, p.args
(<functools.partial object at 0x100431d60>, (2,))


Proposed patch makes partial(partial(f, 1), 2) return partial(f, 1, 2) instead:
>>> p.func, p.args
(<function f at 0x10055d3a8>, (1, 2))

This patch is partially (no pun intended) motivated by a patch submitted by Christophe Simonis for issue4331. Christophe's patch flattens nested partials for a specific case of using partials as bound methods.

As proposed, the patch will enable flattening for subclasses of functools.partial, but will return a baseclass instance.  Flattening will also discard any state attached to the nested partial such as __name__, __doc__, etc or any subclass data.  I believe this is the right behavior, but this caveat is the reason I classify this patch as a "feature request" rather than "performance" or "resource usage".
History
Date User Action Args
2010-02-01 19:07:31Alexander.Belopolskysetrecipients: + Alexander.Belopolsky
2010-02-01 19:07:31Alexander.Belopolskysetmessageid: <1265051251.66.0.305258896073.issue7830@psf.upfronthosting.co.za>
2010-02-01 19:07:29Alexander.Belopolskylinkissue7830 messages
2010-02-01 19:07:28Alexander.Belopolskycreate