[issue18305] [patch] Fast sum() for non-numbers

Sergey report at bugs.python.org
Fri Jul 12 01:57:52 CEST 2013


Sergey added the comment:

Steven D'Aprano noticed that there's an obscure case of:

>>> class A(list):
...     def __add__(self, other):
...         return A(super(A,self).__add__(other))
...     def __radd__(self, other):
...         return A(other) + self
...

Where:
>>> type( [1] + A([2]) )
<class '__main__.A'>

Is different from:

>>> type( [1].__add__(A([2])) )
<class 'list'>

To keep such an undefined behavior unchanged I updated the fastsum-special-tuplesandlists.patch to have a more strict type check.

In case somebody would like to test it, the patch is attached. It should work for both Python 2.7 and Python 3.3, and should introduce no behavior change.

----------
Added file: http://bugs.python.org/file30897/fastsum-special-tuplesandlists.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18305>
_______________________________________


More information about the Python-bugs-list mailing list