[Python-ideas] Should this be considered a bug?

Carl M. Johnson cmjohnson.mailinglist at gmail.com
Sun Oct 30 12:08:31 CET 2011


On Oct 30, 2011, at 12:55 AM, Nick Coghlan wrote:

> On Sun, Oct 30, 2011 at 8:29 PM, Mike Meyer <mwm at mired.org> wrote:
>> 
>> h = [1, 2, 3]
>> d = dict(a=1, b=2)
>> h += d # works
>> h = h + d # exception
> 
> No, the reason the latter fails is because it's unclear what the type
> of the result should be and the interpreter refuses to guess. In the
> former case, there's no such ambiguity (since the type of 'h' simply
> stays the same).

What about the fact that dictionaries have no particular order? If you're expecting my_list += my_set to come out in a particular order (a common rookie mistake when dealing with dicts as well), you can be silently bitten. 


More information about the Python-ideas mailing list