[New-bugs-announce] [issue29139] operator.concat/iconcat could only work if left operand is a sequence
Xiang Zhang
report at bugs.python.org
Tue Jan 3 04:58:30 EST 2017
New submission from Xiang Zhang:
As the title, but I think it should also continue if only the right operand is a sequence since the right operand could get a __radd__ to do the concatenation:
>>> class S:
... def __init__(self):
... self.v = list(range(10))
... def __radd__(self, other):
... print('in __radd__')
... self.v.extend(other)
... return self.v
... def __getitem__(self, idx):
... return self.v[idx]
>>> def i():
... yield from range(10, 20)
>>> i() + S()
in __radd__
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
>>> operator.concat(i(), S())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'generator' object can't be concatenated
>>> a = i()
>>> a += S()
in __radd__
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
>>> a = i()
>>> operator.iconcat(a, S())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'generator' object can't be concatenated
----------
components: Library (Lib)
messages: 284546
nosy: xiang.zhang
priority: normal
severity: normal
status: open
title: operator.concat/iconcat could only work if left operand is a sequence
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29139>
_______________________________________
More information about the New-bugs-announce
mailing list