[Python-ideas] dictionary constructor should not allow duplicate keys

Michael Selik michael.selik at gmail.com
Tue May 3 15:21:01 EDT 2016


On Mon, May 2, 2016 at 5:36 PM Luigi Semenzato <luigi at semenzato.com> wrote:

> For context, someone ran into this problem in my team at Google (we
> fixed it using pylint). I haven't seen any valid reason (in the bug
> or elsewhere) in favor of these constructor semantics. From the
> discussions I have seen, it seems just an oversight in the
> implementation/specification of dictionary literals.  I'd be happy to
> hear stronger reasoning in favor of the status quo.
>

Do you feel that "prefer status quo" is not strong reasoning?
http://www.curiousefficiency.org/posts/2011/02/status-quo-wins-stalemate.html

Your word choice of "[no] valid reason" is interesting. In the bug tracker
discussion, folks argue that the problem is easily solved with code style
standards and static analyzers. I thought that was valid.

Rob Cliffe mentioned the fact that repeated keyword arguments causes a
syntax error. I see the parallel here, except that keyword arguments must
be valid identifiers. Literal dicts syntactically may have any expression
as the key. Creating a special case for the parser to enforce uniqueness of
number and string literals as keys seems more trouble than its worth.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160503/84611774/attachment.html>


More information about the Python-ideas mailing list