Message130925
| Author |
terry.reedy |
| Recipients |
Carl.Friedrich.Bolz, Trundle, arigo, daniel.urban, eric.araujo, meador.inge, ncoghlan, terry.reedy |
| Date |
2011年03月14日.23:03:43 |
| SpamBayes Score |
3.6890935e-06 |
| Marked as misclassified |
No |
| Message-id |
<1300143824.86.0.786235090512.issue11477@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|