Message274860
| Author |
lukasz.langa |
| Recipients |
Julian, amaury.forgeotdarc, belopolsky, eric.araujo, lukasz.langa, martin.panter, pitrou, rharris, rhettinger, vencabot_teppoo |
| Date |
2016年09月07日.18:29:48 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1473272989.04.0.313182186216.issue2651@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
No, the suggestion is to only adopt the first part of the patch from 2010, which is to revert KeyError to behave like LookupError again:
>>> print(LookupError('key'))
key
>>> print(KeyError('key'), 'now')
'key' now
>>> print(KeyError('key'), 'in 3.6')
key in 3.6
In other words, there is no descriptive message while stringifying KeyError. Having an API with two arguments was disruptive because it moved the key from e.args[0] to e.args[1].
Raymond, would it be acceptable to create a two-argument form where the *second* argument is the message? That way we could make descriptive error messages for dicts, sets, etc. possible. In this world:
>>> print(KeyError('key', 'key {!r} not found in dict'), 'in 3.6')
key 'key' not found in dict in 3.6
Do you think any code depends on `str(e) == str(e.args[0])`? |
|