[Python-ideas] Thoughts on "extended mapping unpacking"

George Leslie-Waksman waksman at gmail.com
Thu May 24 13:08:28 EDT 2018


I have had plenty of instances where destructuring a mapping would have be
convenient. Relating to iterable destructuring, I would expect the syntax
to be of the form "variable: key". I also think the curly-braces make it
harder to visually parse what's going on. So I might suggest something a
little like:

objkey = object()
mydict = {'a': 1, 'b': 2, 'c': 3, 4: 5, None: 6, objkey: 7}
var1: 'a', var2: 4, var3: None, var4: objkey, **rest = mydict
assert var1 == 1
assert var2 == 5
assert var3 == 6
assert var4 == 7
assert rest == {'b': 2, 'c': 3}

On Thu, May 24, 2018 at 9:37 AM Serhiy Storchaka <storchaka at gmail.com>
wrote:

> 24.05.18 18:46, Neil Girdhar пише:
> >     p = parameters.pop('some_parameter')
> >     q = parameters.pop('some_other_parameter')
> >     if parameters:
> >           raise ValueError
> >
> > parameters is a Mapping subclass and I don't want to destroy it
>
> Oh, right. It works if parameters is a var-keyword parameter.
>
>      def __init__(self, some_kwarg, some_other_kwargs, **parameters):
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180524/9edb0f10/attachment.html>


More information about the Python-ideas mailing list