[issue2651] Strings passed to KeyError do not round trip

Amaury Forgeot d'Arc report at bugs.python.org
Mon Apr 21 02:15:03 CEST 2008


Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:

Attached patch changes KeyError: when it has two arguments, they are
formatted with "%s: %r". Otherwise the base repr is called, and this
allows the round trip.

Standard objects (dict, set, UserDict, namedtuple, defaultdict, weak
dictionaries) now raise something like KeyError("not in dict", key). 

At least one place in the stdlib relied on the key being the first
argument to KeyError() (in ConfigParser.py)

I don't know if this incompatibility will break much code. At least we
can say that the current behavior is not documented.

----------
keywords: +patch
Added file: http://bugs.python.org/file10069/KeyError.patch

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2651>
__________________________________


More information about the Python-bugs-list mailing list