Raymond Hettinger added the comment:
A negative value will almost never be the cause of this exception.
The proposed new message is more accurate but is also less useful and
informative. Getting a ValueError exception already means "the value is
invalid". The job of the message is to suggest the likely cause so a person
will no what to do about it.
That said, I'll tweak the message at some point but I'm rejecting the patch
as-is because I believe it makes the message worse rather better.
Please do keep looking for ways to improve Python's error messages and make
them as useful as possible.
Here's food for thought: In Py2.x, the error message for len(obj) is different
depending on whether it is a new-style or old-style class. If someone has
forgotten to add the appropriate magic method to their class, which message
would be the most helpful:
>>> class A(object): pass
>>> len(A())
Traceback (most recent call last):
...
TypeError: object of type 'A' has no len()
>>> class A: pass
>>> len(A())
Traceback (most recent call last):
...
AttributeError: A instance has no attribute '__len__'
----------
resolution: -> rejected
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue17388>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com