Xiang Zhang added the comment:

> 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__')

----------

_______________________________________
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

Reply via email to