On Sat, Apr 18, 2020 at 09:13:44PM +0200, Dominik Vilsmeier wrote:

> 
>     func(foo, **, bar)          vs.          func(foo, **{bar})
> 
> It's still a mode switch, only the beginning and end markers have
> changed. Instead of `**,` (or `**mapping,`) we then have `**{` as the
> opening marker and instead of `)` (the parenthesis that closes the
> function call) we have `}` as the closing marker.

How do you define a mode switch?

Is a list display a mode? Is a string a mode? Is a float a mode?

In some sense, maybe, but to me the critical factor is that nobody talks 
about "list mode", "string mode", let alone "float mode". Its about the 
mental model.

With `func(foo, **, bar, baz, quux)` if I use `**` as a pseudo-argument, 
the interpreter switches to "auto-fill" mode and everything that follows 
that (until the end of the function call) has to be interpreted 
according to the mode.

A few people immediately started describing this as a mode, without 
prompting. I think it is a very natural way of thinking about it.

And we have no way of turning the mode off. So if there is every a 
proposal to allow positional arguments to follow keyword arguments, it 
won't be compatible with auto-fill mode.

With `func(foo, **{bar, baz, quux})` the mental model is closer to 
ordinary argument or dict unpacking. Nobody refers to this:

    func(spam, *[eggs, cheese, aardvark], hovercraft)

as "list mode" or "argument unpacking mode". It's just "unpacking a 
list" or similar. No-one thinks about the interpreter entering a special 
"collect list mode" even if that's what the parser actually does, in 
some sense. We read the list as an entity, which then gets unpacked.

Likewise for dict unpacking: nobody thinks of `{'a': expr}` as entering 
"dict mode". You just make a dict, then unpack it.

And nobody (I hope...) will think of keyword shortcut as a mode:

    func(foo, **{bar, baz}, quux=1)`

It's just unpacking an autofilled set of parameter names. Not a mode at 
all. And notice that there is absolutely no difficulty with some future 
enhancement to allow positional arguments after keyword arguments.


-- 
Steven
_______________________________________________
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/TAWUKFIFC5TG7EEYFR6H4SH3ZASH3FAT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to