For what it's worth, I was just writing the following today, and Steven's
proposal came to mind.

If we ignore the set of questionable (but realistic) decisions that led to
me having to do the following, and the discussion on how the unpacking
syntax would look:

---[ wot I wrote ] ---
    if request.method == 'POST':
        results = {}
        for item in request.json:
            thing = item['thing']
            if item['kind'] == 'ignore':
                results[thing] = ('ignore', None)
            else:
                results[thing] = (item['kind'], item['alternate'])

--- [dict unpacking version] ---
    if request.method == 'POST':
        results = {}
        for item in request.json:
            thing, kind, alternate = **item
            results[thing] = (kind_, None if kind == 'ignore' else
alternate)

I'm not using an inline-if expression in the first example, but the
hypothetical second one seems simple enough to support it.

Note: One thing that slightly bothers me about this is the potential for
naming collisions with built-ins  (I.e, I nearly used 'type' instead of
'kind' int the above data generated from javascript)

Steve

On Fri, Oct 23, 2020 at 9:20 AM Alex Hall <[email protected]> wrote:

> On Fri, Oct 23, 2020 at 5:27 AM Steven D'Aprano <[email protected]>
> wrote:
>
>> Background
>> ----------
>>
>> Iterable unpacking assignment:
>>
>>     values = (1, 2, 3)
>>     a, b, c = *values
>>
>> is a very successful and powerful technique in Python.
>>
>
> Your proposed syntax seems to rest on being similar to this syntax for
> iterable unpacking. But that asterisk isn't valid syntax, so I'm confused.
>
> This is valid syntax:
>
>     a, b, c, *rest = values
>
> but that doesn't make it make sense to write `... = **values` as you
> suggest. And this is valid:
>
>     a, b, c = [*values]
>
> but that asterisk has nothing to do with assignment.
> _______________________________________________
> Python-ideas mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/QX4RBF2XBYG5LBEPJNZ7LS57HGPD4FHU/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/7TAKJ6DMLF4CMPP4QRQASDMVCU7TE2R7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to