<div dir="ltr">It'd still be possible to do it for literal listed keys only if someone wanted to figure out how to do it at parsing time rather than runtime.</div><br><div class="gmail_quote"><div dir="ltr">On Tue, May 3, 2016 at 12:06 AM Michel Desmoulin <<a href="mailto:desmoulinmichel@gmail.com">desmoulinmichel@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">With Python 3.5, you can unpack in dictionaries:<br>
<br>
d = {**foo, **bar}<br>
<br>
It's now the defacto way of merging 2 dicts, and it requires that you<br>
can use twice the same key for ovious reasons.<br>
<br>
So even if you have good points, it's not possible to do this.<br>
<br>
Le 02/05/2016 23:36, Luigi Semenzato a écrit :<br>
> Hello and sorry if this is an old and over-discussed topic. I could<br>
> not find such discussions here.<br>
><br>
> This was discussed and rejected at <a href="https://bugs.python.org/issue16385" rel="noreferrer" target="_blank">https://bugs.python.org/issue16385</a>,<br>
> but I am not convinced that the discussion presented all arguments<br>
> properly. I tried reopening the bug at<br>
> <a href="http://bugs.python.org/issue26910" rel="noreferrer" target="_blank">http://bugs.python.org/issue26910</a>, but was told I should discuss it<br>
> here instead.<br>
><br>
> The original problem description:<br>
><br>
> lives_in = { 'lion': ['Africa', 'America'],<br>
> 'parrot': ['Europe'],<br>
> #... 100+ more rows here<br>
> 'lion': ['Europe'],<br>
> #... 100+ more rows here<br>
> }<br>
><br>
> The above constructor overwrites the first 'lion' entry silently,<br>
> often causing unexpected behavior.<br>
><br>
> These are the arguments presented in favor of the rejection, followed<br>
> by my rebuttals.<br>
><br>
> 1. "An error is out of the question for compatibility reasons". No<br>
> real rebuttal here, except I wonder if exceptions are ever made and<br>
> under what circumstances. I should point out that a warning may also<br>
> create incompatibilities.<br>
><br>
> 2. "There are ways to rewrite this as a loop on a list". Yes of<br>
> course, but the entire point of the dictionary literal is to offer a<br>
> concise and convenient notation for entering a dictionary as program<br>
> text.<br>
><br>
> 3. "Being able to re-write keys is fundamental to Python dicts and why<br>
> they can be used for Python's mutable namespaces". This is fine but<br>
> it applies to the data structure, not the literal constructor.<br>
><br>
> 4. "A code generator could depend on being able to write duplicate<br>
> keys without having to go back and erase previous output". Yes, but<br>
> it seems wrong to facilitate automated code generation at the expense<br>
> of human code writing. For hand-written code, I claim that in most<br>
> (all?) cases it would be preferable to have the compiler detect key<br>
> duplications. It is easier for an automated code generator to check<br>
> for duplications than it is for a human.<br>
><br>
> 5. "There is already pylint". True, but it forces an additional step.<br>
><br>
> For context, someone ran into this problem in my team at Google (we<br>
> fixed it using pylint). I haven't seen any valid reason (in the bug<br>
> or elsewhere) in favor of these constructor semantics. From the<br>
> discussions I have seen, it seems just an oversight in the<br>
> implementation/specification of dictionary literals. I'd be happy to<br>
> hear stronger reasoning in favor of the status quo.<br>
><br>
> (additional search keywords: dict constructor, dict literal)<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" 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>
><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" 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>