Message107116
"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 |
|
Date |
User |
Action |
Args |
2010-06-05 00:39:35 | terry.reedy | set | recipients:
+ terry.reedy, jackdied, r.david.murray, benrg |
2010-06-05 00:39:35 | terry.reedy | set | messageid: <1275698375.37.0.270594662155.issue8847@psf.upfronthosting.co.za> |
2010-06-05 00:39:33 | terry.reedy | link | issue8847 messages |
2010-06-05 00:39:32 | terry.reedy | create | |
|