[issue25137] Behavioral change / regression? with nested functools.partial

STINNER Victor report at bugs.python.org
Wed Sep 16 09:09:10 CEST 2015


STINNER Victor added the comment:

> In my opinion this is a regression since there's no way to turn off the new behavior.

Well, it depends on your point of view :-) On the performance point of view, it's much faster to flatten heavily nested partials like:

>>> import functools
>>> f = functools.partial(print, 1)
>>> f = functools.partial(f, 2)
>>> f = functools.partial(f, 3)
>>> f = functools.partial(f, 4)
>>> f = functools.partial(f, 5)
>>> f()
1 2 3 4 5

> This is a behavioral change that causes a test failure in Django because we use nested partials to resolve relationships between models

Can you point me to the code? Why do you need to know the full chain of nested partials?

If you need to remember the chain of actions, maybe you can store it manually? You can add an attribute to a functools.partial() object. Or you can create a subclass of functools.partial.

----------
nosy: +haypo

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


More information about the Python-bugs-list mailing list