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: container methods raise KeyError not IndexError
Type: Stage:
Components: Documentation Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: rhettinger, wsanchez
Priority: normal Keywords:

Created on 2005-08-01 20:47 by wsanchez, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg25938 - (view) Author: Wilfredo Sanchez (wsanchez) Date: 2005-08-01 20:47
See: http://www.python.org/doc/2.3.5/ref/sequence-types.html, which 
says, for example, that __getitem__(self, key) should raise an 
IndexError if key is not in the container.

However, built-in dicts raise KeyError instead, and http://
www.python.org/doc/2.3.5/lib/module-exceptions.html#l2h-289 
implies that this is the correct behavior.

This appears to be incorrect in the current documentation as well as 
in the 2.3.5 docs.
msg25939 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-08-01 21:54
Logged In: YES 
user_id=80475

Both the behavior and the docs are correct. However,  the
docs are not especially clear on this point.  Will add a
clarifying note that KeyError is the appropriate error for
mapping types when the key is not found.
msg25940 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-08-21 11:28
Logged In: YES 
user_id=80475

Okay.  Fixed.
History
Date User Action Args
2022-04-11 14:56:12adminsetgithub: 42238
2005-08-01 20:47:44wsanchezcreate