Message7350

Author Arfrever
Recipients Arfrever, fwierzbicki
Date 2012-08-04.05:33:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1344058396.77.0.252912107281.issue1955@psf.upfronthosting.co.za>
In-reply-to
Content
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
>>>
History
Date User Action Args
2012-08-04 05:33:16Arfreversetrecipients: + Arfrever, fwierzbicki
2012-08-04 05:33:16Arfreversetmessageid: <1344058396.77.0.252912107281.issue1955@psf.upfronthosting.co.za>
2012-08-04 05:33:16Arfreverlinkissue1955 messages
2012-08-04 05:33:15Arfrevercreate