[ python-Feature Requests-906746 ] int object need more informative error message

SourceForge.net noreply at sourceforge.net
Fri May 21 12:14:10 EDT 2004


Feature Requests item #906746, was opened at 2004-02-29 03:14
Message generated for change (Comment added) made by arigo
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=906746&group_id=5470

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: George Yoshida (quiver)
Assigned to: Nobody/Anonymous (nobody)
Summary: int object need more informative error message

Initial Comment:
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'


----------------------------------------------------------------------

>Comment By: Armin Rigo (arigo)
Date: 2004-05-21 16:14

Message:
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.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-05-21 06:09

Message:
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.  

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=906746&group_id=5470



More information about the Python-bugs-list mailing list