Description
Many private functions were removed in issue #106320. My plan is to add public functions for removed private functions which are used by 3rd party extensions: see C API: My plan to clarify private vs public functions in Python 3.13.
I don't think that the fact that a private function was used must always justify to directly expose the exact same API to the public C API. Usually, private functions expose implementation details, use weaker or not check such as checking argument types, are not documented, and are not tested.
To make a function public, we should:
-
Follow new C API guidelines to avoid past design mistakes:
- https://devguide.python.org/developer-workflow/c-api/
- PEP 733: An Evaluation of Python's Public C API (it's currently a draft)
- https://github.com/capi-workgroup/api-evolution/issues
- This part is still a work-in-progress, but there is an agreement on some common good practice, like don't return borrowed references, and design the API so the caller doesn't have to check for exception by calling PyErr_Occurred().
-
Document the API.
-
Write some basic unit tests (for non regression). The bare minimum is to make sure that the constant exists and call each function at least once.
I also would like to add new public functions to https://pythoncapi-compat.readthedocs.io/ to provide them to Python 3.12 and older (by calling the old private functions).
This work will take time. Depending on how it goes, we should consider reverting some removals if there is too much pressure, to unblock some critical dependencies.
The target is to make most C extensions compatible with Python 3.13 when Python 3.13 beta1 is released. Obviously, sooner the better.
C extensions which want to access implementation details can use the internal C API. By default, I modified the internal functions to no longer export internal functions, only make them usable by Python internals: they cannot be used by shared libraries such as stdlib C extensions. This part is unclear to me. Should we expose more internal functions. Which ones? How do you decide if a function should be exported or not?