homepage

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.

classification
Title: KeyError exception is more difficult to read due to quoting
Type: Stage: resolved
Components: Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution:
Dependencies: Superseder: Strings passed to KeyError do not round trip
View: 2651
Assigned To: Nosy List: Anthony Sottile, martin.panter
Priority: normal Keywords:

Created on 2020年09月12日 00:17 by Anthony Sottile, last changed 2022年04月11日 14:59 by admin. This issue is now closed.

Messages (2)
msg376754 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2020年09月12日 00:17
For example:
>>> import pwd
>>> pwd.getpwnam("test")
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
KeyError: "getpwnam(): name not found: 'test'"
An improvement would be something which doesn't have the extra set of quotes such as:
>>> import pwd
>>> pwd.getpwnam("test")
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
KeyError: getpwnam(): name not found: 'test'
I understand this is due to the `KeyError` repr, I wonder if something could be done to improve this (maybe a subclass of KeyError? maybe a new optional named-only argument to KeyError?)
Seems there are others which could be improved here as well:
>>> import unicodedata
>>> unicodedata.lookup('zzz')
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
KeyError: "undefined character name 'zzz'"
msg376762 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2020年09月12日 01:57
Perhaps a duplicate of Issue 2651, closed because it was too hard to fix without breaking compatibility.
History
Date User Action Args
2022年04月11日 14:59:35adminsetgithub: 85933
2020年09月12日 02:10:38Anthony Sottilesetstatus: open -> closed
stage: resolved
2020年09月12日 01:57:05martin.pantersetsuperseder: Strings passed to KeyError do not round trip

messages: + msg376762
nosy: + martin.panter
2020年09月12日 00:17:04Anthony Sottilecreate

AltStyle によって変換されたページ (->オリジナル) /