[Python-Dev] Partial function application 'from the right'

Ben North ben at redfrontdoor.org
Tue Feb 3 14:44:53 CET 2009


Hi,

Thanks for the further responses.  Again, I'll try to summarise:

Scott David Daniels pointed out an awkward interaction when chaining
partial applications, such that it could become very unclear what was
going to happen when the final function is called:

> If you have:
>     def button(root, position, action=None, text='*', color=None):
>         ...
>     ...
>     blue_button = partial(button, my_root, color=(0,0,1))
>
> Should partial_right(blue_button, 'red') change the color or the text?

Calvin Spealman mentioned a previous patch of his which took the 'hole'
approach, i.e.:

> [...] my partial.skip patch, which allows the following usage:
>
>    split_one = partial(str.split, partial.skip, 1)

This would solve my original problems, and, continuing Scott's example,

   def on_clicked(...): ...

   _ = partial.skip
   clickable_blue_button = partial(blue_button, _, on_clicked)

has a clear enough meaning I think:

   clickable_blue_button('top-left corner')
   = blue_button('top-left corner', on_clicked)
   = button(my_root, 'top-left corner', on_clicked, color=(0,0,1))

Calvin's idea/patch sounds good to me, then.  Others also liked it.
Could it be re-considered, instead of the partial_right idea?

Ben.


More information about the Python-Dev mailing list