You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to test the Codecs C API (#123343), I need to be able to un-register a custom codecs error policy, otherwise running the tests would leak since they won't clean the registry.
For now, I've managed to make the tests work without this but it's an ugly hack (namely, relying on the fact that the test suite is executed multiple times when searching for refleaks).
The proposed API is as follows:
/* Internal function in Python/internal/pycore_codecs.h */externint_PyCodec_UnregisterError(constchar*name);
/* Exposed private Python function in Modules/_codecsmodule.c */staticint_codecs__unregister_error(PyObject*module, PyObject*name);
It would:
return 0 if the name does not exist (converted into False at Python level)
return 1 if the name exists and was successfully removed (converted into True at Python level)
return -1 and set an exception if someone attemps to unregister a standard error policy (e.g., 'strict') or if the removal failed for whatever reason. The exception in the first case would be a ValueError while the exception in the second case would be the one raised internally (we would just propagate any exception by PyDict_PopString).
EDIT: After discussion, we decided to first make it entirely private and un-documented (documentation still exists at the code level but not in an RST file). If needs arise, we will make it public.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Activity
[-][C API] Add `PyCodec_UnregisterError` to un-register custom error handlers[/-][+][C API] Add private `_PyCodec_UnregisterError` to un-register custom error handlers[/+]gh-124665: Add `_PyCodec_UnregisterError` and `_codecs._unregister_er…
picnixz commentedon Sep 29, 2024
Completed in c00964e.