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 <>
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.

Date User Action Args
2021-02-12 23:10:10sblondonsetrecipients: + sblondon, barry, brett.cannon, rhettinger, mark.dickinson, ezio.melotti, r.david.murray, cvrebert, zingero, platonoff-dev
2021-02-12 23:10:10sblondonsetmessageid: <>
2021-02-12 23:10:10sblondonlinkissue18163 messages
2021-02-12 23:10:10sblondoncreate