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.

Author cvrebert
Recipients cvrebert
Date 2009-04-15.06:32:09
SpamBayes Score 7.915688e-06
Marked as misclassified No
Message-id <1239777131.98.0.31222273519.issue5760@psf.upfronthosting.co.za>
In-reply-to
Content
Prompted by
http://mail.python.org/pipermail/python-ideas/2009-April/004048.html

The current error message issued when trying to use the get item ([])
operator on an object that does not define __getitem__ can be hard to
understand:

>>> class A(object): pass
...
>>> A()['a']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'A' object is unsubscriptable

Problems observed:
- "unsubscriptable" is easily misread in haste as "unscriptable", which
can be quite confusing, especially to newbies
- "subscripting" is not frequently used to describe the [] operator,
making the message more difficult to decipher (again, esp. for newbies)
- the underlying lack of a __getitem__ method is not mentioned, thus not
making it obvious how to remedy the error

Suggestion:
Use exception chaining and rephrase the error message to get something like:

AttributeError: class 'A' has no attribute '__getitem__'
The above exception was the direct cause of the following exception:
TypeError: 'A' object does not support the 'get item' operator

Similar changes should be made to __setitem__ & __delitem__.
History
Date User Action Args
2009-04-15 06:32:12cvrebertsetrecipients: + cvrebert
2009-04-15 06:32:11cvrebertsetmessageid: <1239777131.98.0.31222273519.issue5760@psf.upfronthosting.co.za>
2009-04-15 06:32:10cvrebertlinkissue5760 messages
2009-04-15 06:32:09cvrebertcreate