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.

classification
Title: Behavioral change / regression? with nested functools.partial
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: MarkusH, Tim.Graham, belopolsky, berker.peksag, charettes, ncoghlan, pitrou, python-dev, vstinner
Priority: normal Keywords:

Created on 2015-09-16 01:36 by MarkusH, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (11)
msg250814 - (view) Author: Markus Holtermann (MarkusH) * Date: 2015-09-16 01:36
Since #7830 nested partials are flattened. This is a behavioral change that causes a test failure in Django because we use nested partials to resolve relationships between models: https://github.com/django/django/pull/4423#issuecomment-138996095

In my opinion this is a regression since there's no way to turn off the new behavior.
msg250819 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2015-09-16 07:01
The specific attributes of a partial are not documented, so it is you are relying on them. Using partial as a container is also a bit unexpected...
msg250820 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-16 07:09
> 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.
msg250860 - (view) Author: Tim Graham (Tim.Graham) * Date: 2015-09-16 18:51
We can use an alternate approach in Django, if appropriate: https://github.com/django/django/pull/5294
msg250980 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-18 13:20
Can we close this issue?
msg250988 - (view) Author: Tim Graham (Tim.Graham) * Date: 2015-09-18 13:54
It's fine with me.
msg250989 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-18 13:55
Tim Graham wrote: "It's fine with me."

Oh, I see that your pull request was merged. I'm now closing the issue.

Anyway, thanks for the bug report. It's always good to have feedback on behaviour changes, even when they are legit :-)
msg250991 - (view) Author: Markus Holtermann (MarkusH) * Date: 2015-09-18 14:14
Interesting thing tough, this optimization is nowhere mentioned in the 3.5 release notes ;)
msg251300 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-22 10:09
New changeset fa766b6f12b5 by Berker Peksag in branch '3.5':
Issue #25137: Add a note to whatsnew/3.5.rst for nested functools.partial calls
https://hg.python.org/cpython/rev/fa766b6f12b5

New changeset ed694938c61a by Berker Peksag in branch 'default':
Issue #25137: Add a note to whatsnew/3.5.rst for nested functools.partial calls
https://hg.python.org/cpython/rev/ed694938c61a
msg251301 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-09-22 10:10
Added a note to Doc/whatsnew/3.5.rst.
msg251306 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-22 10:34
Thanks for the doc Berker :-)
History
Date User Action Args
2022-04-11 14:58:21adminsetgithub: 69324
2015-09-22 10:34:04vstinnersetmessages: + msg251306
2015-09-22 10:10:38berker.peksagsetnosy: + berker.peksag

messages: + msg251301
stage: resolved
2015-09-22 10:09:12python-devsetnosy: + python-dev
messages: + msg251300
2015-09-18 14:14:00MarkusHsetmessages: + msg250991
2015-09-18 13:55:33vstinnersetstatus: open -> closed
resolution: not a bug
messages: + msg250989
2015-09-18 13:54:10Tim.Grahamsetmessages: + msg250988
2015-09-18 13:20:39vstinnersetmessages: + msg250980
2015-09-16 18:51:59Tim.Grahamsetmessages: + msg250860
2015-09-16 07:09:10vstinnersetnosy: + vstinner
messages: + msg250820
2015-09-16 07:01:24pitrousetmessages: + msg250819
2015-09-16 02:20:23charettessetnosy: + charettes
2015-09-16 02:00:51rhettingersetnosy: + ncoghlan, pitrou
2015-09-16 01:46:26Tim.Grahamsetnosy: + Tim.Graham
2015-09-16 01:36:32MarkusHcreate