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 <rep...@bugs.python.org> <http://bugs.python.org/issue29139> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com