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

Chris Angelico rosuav at gmail.com
Tue May 3 23:04:50 EDT 2016

On Wed, May 4, 2016 at 12:44 PM, Random832 <random832 at fastmail.com> wrote:
> On Tue, May 3, 2016, at 22:22, Chris Angelico wrote:
>> Whether constants get folded before this check, and whether {1:'x',
>> 1.0:'y'} causes an error, can be implementation-defined.
> For *general* constant folding, maybe, but what's the point of having it
> if it doesn't apply to negative numbers and nonimaginary complex
> numbers? How about tuple displays consisting of only numeric and string
> literals, empty tuple displays, and tuple displays which themselves
> satisfy this definition?

That's why I say implementation-defined. I would generally expect -5
to count as a literal, but if (2+3) or ("a", "b") doesn't, so be it.

Of course, I would expect 'a' and "a" to be seen as identical.
Likewise 100 and 0x64. Beyond that, it's basically up to whatever the
implementation finds easy; as long as the keys *would be* folded, and
are literals, it's permissible to raise the error.


More information about the Python-ideas mailing list