This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Julian, amaury.forgeotdarc, belopolsky, eric.araujo, lukasz.langa, martin.panter, pitrou, rharris, rhettinger, terry.reedy, vencabot_teppoo
Date 2017-10-23.23:37:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1508801824.67.0.213398074469.issue2651@psf.upfronthosting.co.za>
In-reply-to
Content
A new Stackoverflow question gives a better illustration of how special-casing KeyError can be a nuisance.
https://stackoverflow.com/questions/46892261/new-line-on-error-message-in-idle-python-3-3/46899120#46899120
From a current repository build instead of 3.3:

>>> s = 'line\nbreak'
>>> raise Exception(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Exception: line
break
>>> raise KeyError(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'line\nbreak'
>

The OP wanted to get the line break to break without fudging the code to catch Exception rather than KeyError.  I proposed catching KeyError and then 'print(err.args[0]' instead of 'print(err)'.

Why this makes a difference, and why KeyError is unique in needing this, is obvious after I found this issue and read the code comment quoted by Amaury.  But it sure wasn't before.

The rational for applying repr only applies when there is exactly one arg of value ''.  So I think the fix should be to only apply it when args *is* ('',).  There is no reason to quote a non-blank message -- and suppress any formatting a user supplies.
History
Date User Action Args
2017-10-23 23:37:04terry.reedysetrecipients: + terry.reedy, rhettinger, amaury.forgeotdarc, belopolsky, pitrou, rharris, eric.araujo, vencabot_teppoo, lukasz.langa, Julian, martin.panter
2017-10-23 23:37:04terry.reedysetmessageid: <1508801824.67.0.213398074469.issue2651@psf.upfronthosting.co.za>
2017-10-23 23:37:04terry.reedylinkissue2651 messages
2017-10-23 23:37:04terry.reedycreate