Message5861
I agree that it's a bug. The whole point of __r*__ methods is to add support for operations in reversed situation where first class doesn't know about the second. If works perfectly fine in CPython:
class Foo (object):
def __add__(self, that):
print self, that
def __radd__(self, that):
print self, that
[] + Foo ()
Foo () + []
This never throws TypeError.
The correct behavior for PyArray is to _return_ NotImplemented, not raise a TypeError. E.g. consider the following example:
class Foo (object):
def __add__(self, that):
return NotImplemented
def __radd__(self, that):
return NotImplemented
class Bar (object):
def __add__(self, that):
print self, that
def __radd__(self, that):
print self, that
Foo () + Bar ()
Bar () + Foo ()
Foo () + 1
Class Foo is declared to never allow any addition whatsoever. However, Bar can override this with __radd__ method and it works fine. But the last statement fails, because neither Foo.__add__(int) nor int.__radd__(Foo) produces a result:
Traceback (most recent call last):
File "/home/developer/test/test.py", line 15, in <module>
Foo () + 1
TypeError: unsupported operand type(s) for +: 'Foo' and 'int' |
|
Date |
User |
Action |
Args |
2010-06-29 10:17:12 | doublep | set | messageid: <1277806632.0.0.670401499355.issue1622@psf.upfronthosting.co.za> |
2010-06-29 10:17:11 | doublep | set | recipients:
+ doublep, akong, babelmania |
2010-06-29 10:17:11 | doublep | link | issue1622 messages |
2010-06-29 10:17:10 | doublep | create | |
|