[ python-Bugs-1249837 ] container methods raise KeyError not IndexError

SourceForge.net noreply at sourceforge.net
Mon Aug 1 23:54:38 CEST 2005


Bugs item #1249837, was opened at 2005-08-01 15:47
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1249837&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Documentation
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Wilfredo Sanchez (wsanchez)
>Assigned to: Raymond Hettinger (rhettinger)
Summary: container methods raise KeyError not IndexError

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

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

>Comment By: Raymond Hettinger (rhettinger)
Date: 2005-08-01 16:54

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

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

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


More information about the Python-bugs-list mailing list