Message7350
When special methods (e.g. __add__ or __sub__) return NotImplemented, then operations which internally use these methods should raise appropriate TypeError exceptions.
In CPython:
>>> class A:
... def __add__(self, other):
... return NotImplemented
... def __sub__(self, other):
... return NotImplemented
...
>>> A() + A()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'instance' and 'instance'
>>> A() - A()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'instance' and 'instance'
>>>
In Jython:
>>> class A:
... def __add__(self, other):
... return NotImplemented
... def __sub__(self, other):
... return NotImplemented
...
>>> A() + A()
NotImplemented
>>> A() - A()
NotImplemented
>>> |
|
Date |
User |
Action |
Args |
2012-08-04 05:33:16 | Arfrever | set | recipients:
+ Arfrever, fwierzbicki |
2012-08-04 05:33:16 | Arfrever | set | messageid: <1344058396.77.0.252912107281.issue1955@psf.upfronthosting.co.za> |
2012-08-04 05:33:16 | Arfrever | link | issue1955 messages |
2012-08-04 05:33:15 | Arfrever | create | |
|