Message284549
> You can use operator.add() if you need to fall back to a __radd__ of the right operand.
IMHO for sequences when defining __add__, __radd__, there is no difference between addition and concatenation, just as https://docs.python.org/3/reference/datamodel.html#emulating-container-types states. So it's confusing for me why must I use operator.add not operator.concate?
> operator.concat() is Python API to the sq_concat slot. It falls back to __add__() just because instances of user classes defining an __add__() method only have an nb_add slot, not an sq_concat slot.
More like a implementation detail for me. Users writing only Python won't realize such things.
> Third-party classes (maybe NumPy arrays, I don't know) can have different implementations of sq_concat and nb_add.
Does this matter? Anyway operator.concat will fall to '+'. My intent is proposing something like:
if not hasattr(a, '__getitem__') and not hasattr(b, '__getitem__') |
|
Date |
User |
Action |
Args |
2017-01-03 11:07:49 | xiang.zhang | set | recipients:
+ xiang.zhang, vstinner, zach.ware, serhiy.storchaka |
2017-01-03 11:07:48 | xiang.zhang | set | messageid: <1483441668.99.0.123196699002.issue29139@psf.upfronthosting.co.za> |
2017-01-03 11:07:48 | xiang.zhang | link | issue29139 messages |
2017-01-03 11:07:48 | xiang.zhang | create | |
|