
On 18.04.20 08:14, Steven D'Aprano wrote:
This proposal is an alternative to Rodrigo's "Keyword arguments self-assignment" thread.
Rodrigo, please feel free to mine this for useful nuggets in your PEP.
(I don't claim to have invented the syntax -- I think it might have been Alex Hall?)
Keyword Unpacking Shortcut --------------------------
Inside function calls, the syntax
**{identifier [, ...]}
expands to a set of `identifier=identifier` argument bindings.
I don't see how this proposal is significantly different from the `**` version: 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. You have criticized the use of modal interfaces in this message from which I quote (https://mail.python.org/archives/list/python-ideas@python.org/message/TPNFSJ...):
Modes are okay when they are really big (e.g. "I'm in Python programming mode now") but otherwise should be minimized, with an obvious beginning and end. If you have to have a mode, they should be *really obvious*, and this isn't. There's a really fine difference between modes:
my_super_function_with_too_many_parameters( args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, kwargs, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, *, pass_fds, encoding, errors, text, file, mode, buffering, newline, closefd, opener, meta, private, dunder, invert, ignorecase, ascii_only, seed, bindings, callback, log, font, size, style, justify, pumpkin, )
If you miss the star in the middle of the call, there's no hint in the rest of the call to clue you in to the fact that you changed modes.
(The above example uses `*` as the marker, while in the meantime `**` has been proposed.) I'm not convinced that `**{` and `}` make the beginning and end of the mode "really obvious": my_super_function_with_too_many_parameters( args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, kwargs, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, **{pass_fds, encoding, errors, text, file, mode, buffering, newline, closefd, opener, meta, private, dunder, invert, ignorecase, ascii_only, seed, bindings, callback, log, font, size, style, justify, pumpkin}) For really long argument lists you can expect the mode switch to be placed on a separate line for the sake of readability and then it's hard to miss either way: my_super_function_with_too_many_parameters( args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, kwargs, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, **, pass_fds, encoding, errors, text, file, mode, buffering, newline, closefd, opener, meta, private, dunder, invert, ignorecase, ascii_only, seed, bindings, callback, log, font, size, style, justify, pumpkin, ) In addition to that, more and more advanced IDEs are available and those could easily highlight the "autofill" part that follows the `**` (or `**{`) to help readability.