[issue11477] Bug in code dispatching based on internal slots
Terry J. Reedy
report at bugs.python.org
Tue Mar 15 00:03:44 CET 2011
Terry J. Reedy <tjreedy at udel.edu> added the comment:
I think Nick's point, and one I agree with, is (or amounts to):
'somelist += ob' == 'somelist.__iadd__(ob)' ==
'somelist.extend(ob)' == 'somelist[len(somelist):len(somelist)]=ob'
is defined and should be implemented for all somelist,ob pairs. If ob is an iterable, add the items at the end; if not, raise TypeError.
CPython currently has a bug that breaks the middle equality in a peculiar case. We recognize that and hope to fix it.
The proper, future-proof fix for Greg Price & Co. is for them to
1. use somelist.append(ob) to append a single object, iterable or not, to somelist. If they insist on (mis)using += for appending,
2. add the trivial __iter__ yielding just the instance to all classes whose instances are ever a target of 'somelist += instance'. Or
3. wrap each non-iterable instance in an iterable, such as a tuple:
"somelist += (non-iterable,).
Any of these (1. actually) should have been done in the first place, as has always been documented.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11477>
_______________________________________
More information about the Python-bugs-list
mailing list