[Python-ideas] Should this be considered a bug?
solipsis at pitrou.net
Sun Oct 30 12:16:38 CET 2011
On Sun, 30 Oct 2011 12:10:39 +0100
Georg Brandl <g.brandl at gmx.net> wrote:
> 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
I think list.__iadd__ is simply the same as list.extend, which takes
an arbitrary iterable (and therefore accepts dicts, sets, etc.).
More information about the Python-ideas