[Python-Dev] Should KeyError use repr() on its argument?

Guido van Rossum guido@python.org
Tue, 03 Sep 2002 15:57:00 -0400


> The KeyError exception doesn't apply repr() to its argument.  That's
> annoying in cases like this:
> 
>   >>> a = {}
>   >>> a['']
>   Traceback (most recent call last):
>     File "<stdin>", line 1, in ?
>   KeyError
>   >>> 
> 
> Should this be fixed?  How?  (I guess we could add a KeyError__str__
> method to exceptions.c that applies repr().)
> 
> I've got a feeling this is a feature, but not a very useful one.

I take it back.  args[0] being the actual key that failed is a
feature.  str() not using repr() on args[0] is a bug.  I'll fix it.

--Guido van Rossum (home page: http://www.python.org/~guido/)