On 16.04.20 22:28, Alex Hall wrote:
On Thu, Apr 16, 2020 at 10:13 PM Kyle Stanley <aeros167@gmail.com> wrote:
Dominik Vilsmeier wrote:
> I'm not sure if this is doable from the compiler perspective, but what
> about allowing tuples after `**` unpacking:
>      requests.post(url, **(data, params))
>      # similar to
>      requests.post(url, data=data, params=params)

+1. I can see the practical utility of the feature, but was strongly against the
other syntax proposals so far. IMO, the above alternative does a great job of
using an existing feature, and I think it would be rather easy to explain how
it works.

If we go in that direction, I'd prefer curly braces instead so that it's more reminiscient of a dict instead of a tuple, although technically it will look like a set literal.
Do you intend this "shortcut" syntax to also work in other contexts? Because indeed if it looks like a set literal it would be confusing if it emerges as a dict.

Some other possible syntaxes for a dict (which would have to be unpacked in a function call) with string keys equal to the variable name, i.e. {"foo": foo, "bar": bar}:

{*, foo, bar}
This looks like someone forgot an iterable after the `*`.
{**, foo, bar}
This resembles **kwargs but using it to unpack keyword arguments it looks weird: `func(**{**, foo, bar})`.
{:, foo, bar}
{{ foo, bar }}
This is already valid syntax and attempts to store a set inside another set.
{* foo, bar *}
The `*foo` part is already valid syntax and the `bar *` looks like someone forgot the second operand for the binary multiply.
{: foo, bar :}
{: foo, bar}

Personally in these cases I usually write dict(foo=foo, bar=bar) instead of a dict literal because I don't like the quotes, but even then I'm sad that I have to write the word 'dict'. So I would prefer that we covered raw dicts rather than function calls, or both.
If at all, I'd prefer something like {:foo, :bar}. But anyway this takes the proposal in a different direction.

Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/SATYP4EW2ONMA4TFVFLWNILHTBWU3TNG/
Code of Conduct: http://python.org/psf/codeofconduct/