[Patches] [Patch #101839] better error messages

noreply@sourceforge.net noreply@sourceforge.net
Thu, 19 Oct 2000 20:33:05 -0700


Patch #101839 has been updated. 

Project: 
Category: core (C code)
Status: Open
Summary: better error messages

Follow-Ups:

Date: 2000-Oct-08 20:20
By: ping

Comment:
This patch tries to make the feedback from error
messages more consistent and helpful.

For example:

>>> os.kf
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'os' module has no attribute 'kf'
>>> int(a=3)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: int() takes no keyword arguments
>>> class Foo: pass
... 
>>> Foo.spam
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: class Foo has no attribute 'spam'
>>> Foo().spam
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: Foo instance has no attribute 'spam'
>>> Foo()()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: Foo instance has no __call__ method

This isn't really a bug, but it's not a feature either.
I wanted to get it in before the Monday freeze.
If you have time, have a look; i'll leave it to your
judgement whether it's okay to check in.  I know
it's close to the wire, but it's effectively small:
there are no changes in logic, only strings edited
here and there.

The corresponding changes to the tests that
relied on specific wording of error messages
are also included.

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

Date: 2000-Oct-08 20:26
By: ping

Comment:
More examples: 

>>> import os
>>> del os.kf
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'os' module has no attribute 'kf'
>>> pow(3,4,0)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: pow() arg 3 cannot be 0
>>> os.execv('a', 3)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: execv() arg 2 must be a tuple or list
>>> os.execv('a', (3,4))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: execv() arg 2 must contain only strings
>>> 0 ** -4
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ZeroDivisionError: cannot raise 0 to a negative power
>>> int("45", 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: int() base must be >= 2 and <= 36
>>> ord(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: ord() expected string or Unicode character, int found

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

Date: 2000-Oct-08 20:28
By: ping

Comment:
Forgot to mention that this patch also includes
changed names for audio formats in the
linuxaudiodev module.
-------------------------------------------------------

Date: 2000-Oct-09 05:32
By: gvanrossum

Comment:
Sorry, but this has to go in after 2.0 final is released.
It's touching way too much code to be snuck in at the very last moment.
-------------------------------------------------------

-------------------------------------------------------
For more info, visit:

http://sourceforge.net/patch/?func=detailpatch&patch_id=101839&group_id=5470