[issue8847] crash appending list and namedtuple
Terry J. Reedy
report at bugs.python.org
Sat Jun 5 02:39:35 CEST 2010
Terry J. Reedy <tjreedy at udel.edu> added the comment:
"can't reproduce" does not inform as to what *did* happen with which code.
More experiments:
foo = str()
TypeError: can only concatenate list (not "str") to list
class s(str): pass
foo = s()
TypeError: Can't convert 'list' object to str implicitly
Why is it trying to do that? Of course, the interpreter can (implicitly) convert list to tuple, which must be what happens in OP example.
The subclasses of tuple and str do not gain an __radd__ method. If we add one
class s(str):
def __radd__(s,o): print('in radd, type(o)')
foo = s()
a = [1] + foo
# prints "in radd <class 'list'>"
no implicit conversion is done.
Reversing tuple and list
class Crasher(list): pass
a = () + Crasher() # or Crasher([1])
print(a, type(a), len(a))
#[] <class 'list'> 0 # or [1] <class 'list'> 1
whereas
a = (1,) + Crasher()
crashes, so not completely symmetrical
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8847>
_______________________________________
More information about the Python-bugs-list
mailing list