On Sat, Jul 27, 2019 at 9:28 PM Steven D'Aprano <steve@pearwood.info> wrote:
If you're going to add support for a placeholder, there is no need to
create a new kind of partial function?

Exactly! This is just an enhanced functools.partial.  An enhancement that has already been done in several 3rd party libraries, in fact.  I like the ellipsis, which most 3rd parties use, but it could be configurable what the sentinel is.  Maybe a default brand new `functools.SKIP` object, but with the docs explaining the way to use the ellipsis for those 99% of users for whom that wouldn't break anything.

Someone posted an example implementation that used a configurable placeholder like this.
 
> Sure we could also use a `lambda` instead
I believe that partial is faster than lambda.

I don't really care about faster.  I think the "partial with placeholder" is simply nicer to read for many cases.  Sure this is a toy, but:

>>> lastname = 'Mertz'
>>> greet_david = partial(print, ..., 'David', lastname)  # In Python 3.9
>>> greet_david('Verwelkoming')
Verwelkoming David Mertz

vs.

>>> greet_david = lambda greeting: print(greeting, "David", lastname)
>>> greet_david('Cześć')
Cześć David Mertz

OK, that's a bad example because we are using it for the side effect too, but I think it illustrates how the more flexible partial() would look better than lambda.


--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.