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

Georg Brandl g.brandl at gmx.net
Sun Oct 30 12:10:39 CET 2011


On 10/30/2011 11: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).

It's still a bit inconsistent though (e.g. it doesn't work with tuple's
__iadd__).

Also, "type stays the same" is not true in other instances, e.g.

i = 1
i += 0.5

Still, I don't think we need to do anything about it.

cheers,
Georg




More information about the Python-ideas mailing list