Issue 1576657: dict keyerror formatting and tuples (original) (raw)

Probably just a minor glitch, but one which caused me half an hour to track down:

d = {1:'x'} v = (1,) d[v] Traceback (most recent call last): File "", line 1, in KeyError: 1

Note the formatting of the error message. It reads '1', not '(1,)' as you would expect.

The example is constructed. In the code I was debugging, I didn't know that v was a tuple and thought it was the integer 1 - so the KeyError itself was somewhat puzzling.

Only after printing the key I found that the lookup failed due to a type error.

This happens in Python 2.4 and 2.5.