[Python-ideas] Passing positional arguments as keyword arguments (to provide function arguments out of order)

Jonathan Goble jcgoble3 at gmail.com
Wed May 15 01:51:43 EDT 2019


On Wed, May 15, 2019 at 1:37 AM Anders Hovmöller <boxed at killingar.net> wrote:
>
> > On 15 May 2019, at 03:07, Robert Vanden Eynde <robertve92 at gmail.com> wrote:
> >
> > Currently if one wants to provide positional arguments after keyword arguments, it's not possible, one must begin with positional arguments [1] or use keyword arguments [2] :
>
> I'm my opinion the goal should be that there is no such thing as positional only arguments in python. It's just a bad idea. No r al arguments that can be both positional or keyword at the call site, or keyword only. Those are good and make sense. Adding a third option is just added complexity.

That's not a realistic goal; there are some use cases, including in
CPython builtins, that cannot be accomplished without positional-only
arguments. For example, the current behavior of the `dict` constructor
is to accept both certain iterables as a positional-only argument
and/or keyword arguments from which a dict can be created. If the
iterable argument was not positional-only, then it would be forced to
consume a keyword (even if the caller passes it as a positional
argument), meaning that that keyword could never be included in
**kwargs and could not become a dict key via keyword arguments.

Additionally, PEP 570 [1], which will add syntax for positional-only
parameters in Python functions, was accepted by Guido last month.

[1] https://www.python.org/dev/peps/pep-0570/


More information about the Python-ideas mailing list