Title: KeyError.__str__ doesn't use repr()
Type: behaviour Severity: normal
Components: Core Versions:
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: leosoto, pjenvey
Priority: Keywords:

Created on 2008-05-25.05:50:29 by leosoto, last changed 2008-05-25.23:37:15 by pjenvey.

File name Uploaded Description Edit Remove
keyerror.patch leosoto, 2008-05-25.05:57:28
msg3202 (view) Author: Leonardo Soto (leosoto) Date: 2008-05-25.05:50:16
On CPython, KeyError.__str__ is special, because it uses repr() of the
exception argument instead of str(). Here is the reason, from  exceptions.c:

       If args is a tuple of exactly one item, apply repr to args[0].
       This is done so that e.g. the exception raised by {}[''] prints
         KeyError: ''
       rather than the confusing
       alone.  The downside is that if KeyError is raised with an
       string, that string will be displayed in quotes.  Too bad.
       If args is anything else, use the default BaseException__str__().

Currently, Jython doesn't match this behaviour.
msg3203 (view) Author: Leonardo Soto (leosoto) Date: 2008-05-25.05:57:27
Patch, including test case attached
msg3206 (view) Author: Philip Jenvey (pjenvey) Date: 2008-05-25.23:37:08
fixed in r4448-4449. I mistakenly didn't notice your patch originally when 
I did this on r4448 (the pep352 branch), that's why I committed a slightly 
different version of the test. Oops
Date User Action Args
2008-05-25 23:37:15pjenveysetstatus: open -> closed
resolution: fixed
messages: + msg3206
nosy: + pjenvey
2008-05-25 05:57:29leosotosetfiles: + keyerror.patch
messages: + msg3203
2008-05-25 05:50:30leosotocreate