[ python-Bugs-848812 ] Inconsistent list.__add__/__addi__.
SourceForge.net
noreply at sourceforge.net
Mon Dec 1 05:46:47 EST 2003
Bugs item #848812, was opened at 2003-11-25 04:50
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=848812&group_id=5470
Category: None
Group: None
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Jeremy Fincher (jemfinch)
Assigned to: Nobody/Anonymous (nobody)
Summary: Inconsistent list.__add__/__addi__.
Initial Comment:
>>> L = [1,2,3]
>>> L + (1,2,3)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: can only concatenate list (not "tuple") to list
>>> L += (1,2,3)
>>> L
[1, 2, 3, 1, 2, 3]
I've always been somewhat annoyed that list.__add__
didn't accept any iterable (just lists), but to have += accept
any iterable but not + is just plain inconsistent.
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-12-01 05:46
Message:
Logged In: YES
user_id=80475
I think Guido said if he had it to do over, += would not be
able to take any iterable. However, that behavior has been
set in stone for several years now and it would be hard to
take away.
The rule for new types like set() is that both | and |=
require the right hand argument to be of the same type.
However, the corresponding spelled out name, set.update()
may take any iterable as a argument. The idea is that:
s |= 'boom'
is more error prone and less clean than
s.update('boom')
----------------------------------------------------------------------
Comment By: Jeremy Fincher (jemfinch)
Date: 2003-12-01 05:38
Message:
Logged In: YES
user_id=99508
Neither google nor the CVS log for Objects/listobject.c turned up
any past discussion or pronouncement on this.
Which behavior is more desirable may not be up for debate, but
it's still highly inconsistent to have += work in places where +
does not.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2003-11-29 03:44
Message:
Logged In: YES
user_id=80475
It's a feature, not a bug. The goal is to eliminate
unattractive, error prone constructions. Probe the archives
for past discussion and pronouncement on this.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=848812&group_id=5470
More information about the Python-bugs-list
mailing list