On 27 Jul 2019, at 21:10, Andrew Barnert email@example.com wrote:
On Jul 27, 2019, at 08:04, Anders Hovmöller firstname.lastname@example.org wrote:
On 27 Jul 2019, at 14:47, Dominik Vilsmeier email@example.com 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)
Those seem like great cases for changing the standard library to use normal parameters! range and pow are both nicer with keyword arguments imo.
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)
Ok now THAT is a compelling argument!
And similarly for itertools.product, min/max, and everything that acts as a proxy like submit.
Also, even for cases like the OP’s where there’s no semantics reason the argument couldn’t have a keyword, there may still be other reasons. When argclinic was added in PEP 436, it was specifically argued that it shouldn’t be used as an opportunity to phase out positional-only params, in part because for many functions the performance cost of keyword processing outweighs the uncommon potential use of the keywords; IIRC, the OP’s specific method was even one of the core examples. And, as PEP 570 points out, METH_FASTCALL makes that potentially true for pure Python functions as well, to the extent that some other stdlib functions might actually want to lose their keyword args.
Well that sounds pretty terrible to me. I’ve tried to write calls with keywords of many many functions in the standard library because it just isn’t really readable with positional :(