<div dir="ltr"><div><span class="im"><div>> So `a, b, c = **mapping` would be perfectly in line with this.<br><br></div></span>Your
 `func` example is a great connection to have made but I would not reach
 the same conclusion.  When calling `func(**some_dict)` we are not 
performing variable assignment but with the `a, b, c = **mapping` we 
would be.  Whereas I accept that `func(**some_dict)` imposes some 
constraints on the nature of the keys in the dict because functions must
 have proper variable names as input parameters, I find it difficult to 
accept a similar constraint on general dict unpacking.<br><br><br></div>Davin<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 26, 2016 at 7:27 AM, Koos Zevenhoven <span dir="ltr"><<a href="mailto:k7hoven@gmail.com" target="_blank">k7hoven@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class=""><font face="monospace, monospace">On Thu, May 26, 2016 at 5:18 AM, Guido van Rossum <<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>> wrote:<br>> On Wed, May 25, 2016 at 6:56 PM, Steven D'Aprano <<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>> wrote:<br>>> On Wed, May 25, 2016 at 01:11:35PM +0000, Michael Selik wrote:<br>>> What is your evidence for this claim? So far I've only seen one real-<br>>> world use-case for this, and that single use-case would be well served<br>>> by a simpler syntax:<br>>><br>>> a, b, c = **mapping<br>><br>> I have to warn here. This looks cool but it does something that AFAIK<br>> no other Python syntax uses -- it takes variable names and does<br>> something to those variables but *also* uses their actual names as<br>> string literals. I agree that the use cases for this seem pretty<br>> sweet, but perhaps we should give it a somewhat different syntax just<br>> so it's clear that the names on the LHS matter. The precedent that the<br>> targets must be actual names rather than anything you can assign to is<br>> also kind of scary.</font><div><font face="monospace, monospace"><br></font></div></span><div><font face="monospace, monospace">I understand the concern, and maybe you are right. However<div class="gmail_default" style="font-family:monospace,monospace;display:inline">​, this:​</div></font></div><div><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace"><div class="gmail_default" style="font-family:monospace,monospace;display:inline">​    ​</div>def func(y, z, x)</span></div><div><span style="font-family:monospace,monospace"><div class="gmail_default" style="font-family:monospace,monospace;display:inline">​        ​</div>print(x, y, z)</span></div><div><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace"><div class="gmail_default" style="font-family:monospace,monospace;display:inline">​    ​</div>func(**dict(x=1, y=2, z=3))</span></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">prints "1 2 3"<div class="gmail_default" style="font-family:monospace,monospace;display:inline">​, a</div></font><span style="font-family:monospace,monospace">​nd so doe<div class="gmail_default" style="font-family:monospace,monospace;display:inline">​s​</div></span></div><div><span style="font-family:monospace,monospace"><div class="gmail_default" style="font-family:monospace,monospace;display:inline">​    </div></span></div><div><span style="font-family:monospace,monospace"><div class="gmail_default" style="font-family:monospace,monospace;display:inline">    func(x=1, y=2, z=3)​</div></span></div><div><span style="font-family:monospace,monospace"><div class="gmail_default" style="font-family:monospace,monospace;display:inline"><br></div></span></div><div><span style="font-family:monospace,monospace"><div class="gmail_default" style="font-family:monospace,monospace;display:inline">and</div></span></div><div><br></div><div><span style="font-family:monospace,monospace"><div class="gmail_default" style="font-family:monospace,monospace;display:inline">​    func(z=3, x=1, y=2)</div></span></div><div><br></div><div><div class="gmail_default" style="font-family:monospace,monospace">​So `a, b, c = **mapping` would be perfectly in line with this. Of course there may still be confusion, but that would mean the user would probably already be confused about whether dicts are ordered or not, so that confusion would need to be fixed anyway. I think the key is that ** should _never_ be interpreted as unpack/repack by order. Or in other words, it always means unpack/repack _by name_.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">That said, here's a couple of suggestions:</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">    **(a, b, c) = **mapping</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">    **{a, b, c} = **mapping<br></div><div class="gmail_default" style="font-family:monospace,monospace"><br></div></div><div class="gmail_default" style="font-family:monospace,monospace">Although `a, b, c = **mapping` would still be more convenient.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">​-- Koos<br></div><div><div class="gmail_default" style="font-family:monospace,monospace"><br></div></div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">PS. For even more explicitness:</div><div class="gmail_default" style="font-family:monospace,monospace"><div class="gmail_default"><br></div><div class="gmail_default">a from 'a', b from 'b', c from 'c' = **mapping</div><div class="gmail_default"><br></div><div class="gmail_default">Which would allow even</div><div class="gmail_default"><br></div><div class="gmail_default">b from 1, a from 0, x from 2 = **iterable</div><div class="gmail_default"><br></div><div class="gmail_default">Or</div><div class="gmail_default"><br></div><div class="gmail_default">a, b, c from 'a', 'b', 'c' in mapping</div><div class="gmail_default">b, a, c from 1, 0, 2 in mapping </div></div><span class=""><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div><br></div><div><font face="monospace, monospace">><br>> --<br>> --Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)<br>> _______________________________________________<br>> Python-ideas mailing list<br>> <a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>> <a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>> Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br></font><br></div></span></div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br></blockquote></div><br></div>