This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: NotImplemented return value misinterpreted in new classes
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mwh Nosy List: dubnerm, georg.brandl, georg.brandl, mwh
Priority: normal Keywords:

Created on 2003-11-22 02:39 by dubnerm, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg19086 - (view) Author: Michael Dubner (dubnerm) Date: 2003-11-22 02:39
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
msg19087 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-10-01 13:38
Logged In: YES 
user_id=1188172

I could reproduce with all my Pythons. I looked around a bit
but couldn't find any cause of this. Michael, do you have
more luck?
msg19088 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-02-20 19:53
Logged In: YES 
user_id=849994

This now seems to be fixed in 2.5 HEAD and 2.4 branch. Cheers!
History
Date User Action Args
2022-04-11 14:56:01adminsetgithub: 39584
2003-11-22 02:39:43dubnermcreate