David <[email protected]> added the comment:
I'm +1 for fixing this behavior for the same reasons that are mentioned in the
OP: consistency and predictability. I raised this issue as #14086, and I was
referred to this issue before closing mine as a duplicate.
It took me a while to figure out why I was getting unexpected escaped quotation
marks in my strings, and it turned out that it was because I was passing
strings back and forth as Exception arguments (tagging built-in Exceptions with
a little bit of extra information when they occurred and re-raising), and every
time that it occurred with a KeyError (and only with a KeyError), the string
would grow another pair of quotation marks.
In my issue, I bring up the documentation in the Python Tutorial about
Exception.args and Exception.__str__(); it states very plainly and simply (as
it should be) that the __str__() method is there to be able to conveniently
print Exception arguments without calling .args, and, when an unhandled
Exception stops Python, the tail-end of the message (the details) of the
exception will be the arguments that it was given. This is not the case with
KeyError.
str(KeyError("Foo")) should be equal to "Foo", as it would be with any other
Exception and as is the documented behavior of built-in Exceptions, at least in
the tutorial (which I realize isn't the be-all, end-all document). The
documented behavior makes more sense.
----------
nosy: +vencabot_teppoo
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue2651>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com