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: int object need more informative error message
Type: enhancement Stage:
Components: None Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: arigo, nascheme, quiver, rhettinger
Priority: normal Keywords:

Created on 2004-02-29 03:14 by quiver, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg54108 - (view) Author: George Yoshida (quiver) (Python committer) Date: 2004-02-29 03:14
When int objects encounter a NotImplementedError, 
they don't say much about what the problem is and are 
too unfriendly.

Error messages can be more verbose.

>>> reduce(int.__add__, (1, 2L))
NotImplemented

>>> reduce(int.__add__, (1L, 2))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: descriptor '__add__' requires a 'int' object but 
received a 'long'
msg54109 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-05-21 06:09
Logged In: YES 
user_id=80475

Unfortunately, there may not be any flexibility here.  Instead 
of being just an error message, NotImplemented is a 
constant that has meaning to other layers of code.  I don't 
see a way to change this or even attach a more informative 
error message.  
msg54110 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2004-05-21 16:14
Logged In: YES 
user_id=4771

What you report are not error messages generated by
integers, but part of a general internal mecanism.

The golden rule with all __xxx__ special methods is that
they should not be called directly.  This is especially true
for binary methods like __add__ which have pretty complex
internal semantics.  The expression x+y is not equivalent to
x.__add__(y): roughly, althought it first tries
x.__add__(y), it checks if this returned NotImplemented and
calls y.__radd__(x) if it did.  But there are a number of
subtle rules and special cases.

All special methods are meant to be called by language
operators (e.g. x+y, `x`,...); for special usages like
reduce(), all operators are also available as built-in
functions either directly (e.g. repr) or in the module named
'operator' (e.g. operator.add).

Finally, unbound method objects like int.__add__ are not to
be used unless one is really aware of what is going on.
msg54111 - (view) Author: Neil Schemenauer (nascheme) * (Python committer) Date: 2004-05-21 18:48
Logged In: YES 
user_id=35752

Armin is completely correct.  One more point is that
NotImplemented is not the same as NotImplementedError.  The
name similarity is unfortunate because they really have no
relation.  I'm marking the the bug as invalid as I don't
think there is anything to fix.
History
Date User Action Args
2022-04-11 14:56:03adminsetgithub: 39993
2004-02-29 03:14:25quivercreate