On 2019-07-27 20:10, Andrew Barnert via Python-ideas wrote:
On Jul 27, 2019, at 08:04, Anders Hovmöller <bo...@killingar.net> wrote:
On 27 Jul 2019, at 14:47, Dominik Vilsmeier <dominik.vilsme...@gmx.de> wrote:
currently, regarding positional arguments, `partial` gives us the option to
partialize functions from the left. There's been some interest about
partializing functions from the right instead (e.g. [SO post, 9k views, 39
upvotes](https://stackoverflow.com/q/7811247/3767239)), especially w.r.t. the
various `str` methods.
Do you have other examples? That (and most likely similar) examples are just that the standard library contains methods and functions that could be fixed to accept keyword arguments. This would be less confusing and more coherent.
Many of the compelling examples for PEP 570 are good examples here. The
following are all impossible intentionally, and for different reasons:
skipper = partial(range, step=n)
powbase = partial(pow, mod=base)
clscheck = partial(isinstance, class_or_tuple=cls)
Plus, there’s also one very general example: anything that semantically has to
take *args can’t be changed to use keywords:
partial(format, 2=x)
partial(map, 1=x, 2=y)
partial(executor.submit, 1=arg)
And similarly for itertools.product, min/max, and everything that acts as a
proxy like submit.
[snip]
I was thinking that 'partial' is like a function definition, so why not
have a variation on the function definition:
def powbase(x, y) is pow(x, y, base)
def clscheck(obj) is isinstance(obj, cls)
It would capture the current reference of any name that's not passed via
the parameter list, e.g. base and cls in the above examples.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/PIVGTG455RCAKLKSZFY5PMZK7SQJZIMW/
Code of Conduct: http://python.org/psf/codeofconduct/