[Python-3000] Detecting conflicts in dict displays

Terry Reedy tjreedy at udel.edu
Tue Jul 11 09:48:10 CEST 2006


"Steven Bethard" <steven.bethard at gmail.com> wrote in message 
news:d11dcfba0607102211x1be4033sdb42a175bf27e730 at mail.gmail.com...
> On 7/10/06, Guido van Rossum <guido at python.org> wrote:
>> Currently, this is valid:
>>
>>   a = {'a': 1, 'a': 2}
>>   print a     # {'a': 2}
>>
>> I wonder if we shouldn't make this a run-time error instead.
>
> If it's possible, definitely.  That's gotta be a typo if it appears in
> real code.

I think it would overall be helpful to tell people "duplicate key 'a'"

>> If people agree, what should we do with
>>
>>   a = {'a': 1, 'a': 1}
>>
>> ???
>
> It should also be an error.  I can't imagine that not being a typo.
> And there isn't really any reason to write that since we're talking
> dict literals here.

Something effectively the same could also be an act of ignorance:

>>> d={1:'one', 1.0:'one'}
>>> d
{1: 'one'}

I think this should be caught also.  The exception message is a bit 
trickier here.

Terry Jan Reedy





More information about the Python-3000 mailing list