[Python-ideas] dictionary constructor should not allow duplicate keys
Michael Selik
michael.selik at gmail.com
Wed May 4 00:20:16 EDT 2016
On Wed, May 4, 2016 at 12:04 AM Nick Coghlan <ncoghlan at gmail.com> wrote:
> As such, the technical change being requested here (at least for
> CPython), is that BUILD_MAP be updated to do a PyDict_Contains()
> check prior to each key insertion, and:
> 1. Report a DeprecationWarning in 3.6
> 2. Report a [RuntimeError? ValueError?] in 3.7+
>
To be clear, this implementation would potentially raise an error in the
random example -- ``{random(): 0, random(): 1}`` -- correct? If so, then
code smell or not, I think that's too much breakage.
We could restrict the PyDict_Contains() call to only enforcing uniqueness
of string or numeric literals, but then we'd still have some oddball
situations:
def a():
return 'a'
{a(): 0, 'a': 1}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160504/458b1670/attachment.html>
More information about the Python-ideas
mailing list