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 | sblondon |
|---|---|
| Recipients | barry, brett.cannon, cvrebert, ezio.melotti, mark.dickinson, platonoff-dev, r.david.murray, rhettinger, sblondon, zingero |
| Date | 2021年02月12日.23:10:10 |
| SpamBayes Score | -1.0 |
| Marked as misclassified | Yes |
| Message-id | <1613171410.44.0.114021321514.issue18163@roundup.psfhosted.org> |
| In-reply-to |
| Content | |
|---|---|
I'm interested by such feature. I see examples of versions of the message provided by KeyError: - sometimes with a message (for example `PyErr_SetString(PyExc_KeyError, "name too long");` at [1]) - sometimes with the missing key (for example `PyErr_SetObject(PyExc_KeyError, key);` at [2]) It explains why there is a difference in the messages in KeyError (as said in previous messages). PyErr_SetString(), PyErr_Format(), PyErr_FormatV() (implemented in Python/errors.c) don't have a parameter to set the missing key. So I think it would be easier to set the missing attribute before calling thoses functions. According to [3], the C PyExc_KeyError matches the Python KeyError exception. So I think to: - Add a 'missing_key' attribute to KeyError_str (in [4]) - Add the missing key to PyExc_KeyError instance before the call of PyErr_SetString(), PyErr_SetObject(), etc. Do you think such strategy is doable? What do you think about it? Is it the way you think about it? If not, do you have some hint? I already made some minor patches to cpython but only in the Python part, never in C one. 1: https://github.com/python/cpython/blob/master/Modules/unicodedata.c#L1398 2: https://github.com/python/cpython/blob/master/Python/hamt.c#L2767 3: https://docs.python.org/3/c-api/exceptions.html?highlight=pyerr_format#standard-exceptions 4: https://github.com/python/cpython/blob/master/Objects/exceptions.c#L1569 |
|
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2021年02月12日 23:10:10 | sblondon | set | recipients: + sblondon, barry, brett.cannon, rhettinger, mark.dickinson, ezio.melotti, r.david.murray, cvrebert, zingero, platonoff-dev |
| 2021年02月12日 23:10:10 | sblondon | set | messageid: <1613171410.44.0.114021321514.issue18163@roundup.psfhosted.org> |
| 2021年02月12日 23:10:10 | sblondon | link | issue18163 messages |
| 2021年02月12日 23:10:10 | sblondon | create | |