Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C API] Add private _PyCodec_UnregisterError to un-register custom error handlers #124665

Closed
picnixz opened this issue Sep 27, 2024 · 1 comment
Closed
Assignees
Labels
topic-C-API type-feature A feature request or enhancement

Comments

@picnixz
Copy link
Member

picnixz commented Sep 27, 2024

Feature or enhancement

Proposal:

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 */
extern int _PyCodec_UnregisterError(const char *name);
/* Exposed private Python function in Modules/_codecsmodule.c */
static int
_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).

cc @vstinner

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

Links to previous discussion of this feature:

No response

Linked PRs

@picnixz picnixz added type-feature A feature request or enhancement topic-C-API labels Sep 27, 2024
@picnixz picnixz self-assigned this Sep 27, 2024
@picnixz picnixz changed the title [C API] Add PyCodec_UnregisterError to un-register custom error handlers [C API] Add private _PyCodec_UnregisterError to un-register custom error handlers Sep 28, 2024
@picnixz
Copy link
Member Author

picnixz commented Sep 29, 2024

Completed in c00964e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-C-API type-feature A feature request or enhancement
Projects
Development

No branches or pull requests

1 participant