Issue 1249837: container methods raise KeyError not IndexError (original) (raw)

Issue1249837

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:12 admin set github: 42238
2005-08-01 20:47:44 wsanchez create