This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xiang.zhang
Recipients serhiy.storchaka, vstinner, xiang.zhang, zach.ware
Date 2017-01-03.11:07:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1483441668.99.0.123196699002.issue29139@psf.upfronthosting.co.za>
In-reply-to
Content
> 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__')
History
Date User Action Args
2017-01-03 11:07:49xiang.zhangsetrecipients: + xiang.zhang, vstinner, zach.ware, serhiy.storchaka
2017-01-03 11:07:48xiang.zhangsetmessageid: <1483441668.99.0.123196699002.issue29139@psf.upfronthosting.co.za>
2017-01-03 11:07:48xiang.zhanglinkissue29139 messages
2017-01-03 11:07:48xiang.zhangcreate