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: dict throwing inaccurate KeyError on small tuple keys
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: rhettinger, toidinamai
Priority: normal Keywords:

Created on 2006-12-13 01:48 by toidinamai, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg30796 - (view) Author: Frank Benkstein (toidinamai) Date: 2006-12-13 01:48
When using tuples of length one as keys for the builtin
dictionary the Python runtime raises an inaccurate
KeyError exception that makes some errors hard to find:

Python 2.5 (r25:51908, Dec 12 2006, 18:39:30)
[GCC 4.1.1 (Gentoo 4.1.1-r1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> {"foo":"bar"}[("foo",)]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'foo'

Also the error messages for the empty tuple and None are
indistinguishable:

Python 2.5 (r25:51908, Dec 12 2006, 18:39:30)
[GCC 4.1.1 (Gentoo 4.1.1-r1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> {None:"bar"}[()]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError
>>> {():"bar"}[None]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError

This also seems to be the case for earlier versions of Python.
msg30797 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2006-12-13 02:46
This is a duplicate of bug #1576657 when Georg just fixed.
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44333
2006-12-13 01:48:22toidinamaicreate