Message304851
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. |
|
Date |
User |
Action |
Args |
2017-10-23 23:37:04 | terry.reedy | set | recipients:
+ terry.reedy, rhettinger, amaury.forgeotdarc, belopolsky, pitrou, rharris, eric.araujo, vencabot_teppoo, lukasz.langa, Julian, martin.panter |
2017-10-23 23:37:04 | terry.reedy | set | messageid: <1508801824.67.0.213398074469.issue2651@psf.upfronthosting.co.za> |
2017-10-23 23:37:04 | terry.reedy | link | issue2651 messages |
2017-10-23 23:37:04 | terry.reedy | create | |
|