Following program:
------------------------------ notimpl.py
class CClassic:
def __add__(self, other):
return NotImplemented
def __mul__(self, other):
return NotImplemented
class CNew(object):
def __add__(self, other):
return NotImplemented
def __mul__(self, other):
return NotImplemented
a=CClassic()
try:
print a+2
except Exception, e:
print e
try:
print a*2
except Exception, e:
print e
a=CNew()
try:
print a+2
except Exception, e:
print e
try:
print a*2
except Exception, e:
print e
--------------------------------
Output following (correct) under Python 2.2:
unsupported operand types for +: 'instance' and 'int'
unsupported operand type(s) for *: 'instance' and 'int'
unsupported operand types for +: 'CNew' and 'int'
unsupported operand type(s) for *: 'CNew' and 'int'
And following (wrong) under Python 2.3[.2]:
unsupported operand type(s) for +: 'instance' and 'int'
unsupported operand type(s) for *: 'instance' and 'int'
unsupported operand type(s) for +: 'CNew' and 'int'
NotImplemented
|