On 14.06.2022 11:15, Petr Viktorin wrote:
On 13. 06. 22 17:36, Marc-Andre Lemburg wrote:
In the past we always said: "_Py* is an internal API. Use at your own risk.", which I guess is somewhere between the warning and the strict "don't use" policy you are describing.
The problem with the "don't use" policy is that in some cases, there are no public APIs available to do certain things and so the extension writers have to resort to the private ones to implement their logic.
E.g. to implement a free list for Python objects, you have to use _Py_NewReference() in order to create an object based on a memory area taken from the free list. If you want to create a bytes objects using overallocation, it's common to use _PyBytes_Resize() to resize the buffer to the final size.
What sometimes happens is that after a while the private APIs get their leading underscore removed to then become public ones.
It's not just about removing the underscore: when this happens the APIs should also get documentation, tests, and some expectation of stability (e.g. that we won't go randomly adding tstate parameters to them).
Of course; all public APIs should ideally have this :-)
This upwards migration path would be made impossible with the "don't use" policy.
Why not? I have no doubt people will use private API, no matter how explicitly we say that it can break at any time.
My proposal is making this more explicit. And yes, it's also putting some more pressure on core devs to expose proper API for use cases people have, and on people to report their use cases.
It would certainly be good to get more awareness for common uses of currently private APIs, but I'm not sure whether the proposed "don't use" policy would help with this.
I have a feeling that the effect would go in a different direction: with a strict "don't use" policy core devs would get a blanket permission to change exposed _Py* APIs at will, without any consideration about breaking possible use cases out there.
IMO, both parties should be aware of the issues around using/changing exposed APIs marked as private and ideally to the same extent.
Perhaps it would be better to leave the current "use at your own risk" approach in place and just add a new process for potentially having private APIs made public.
E.g. the above two cases are potentially candidates for such a process. I have used both in code I have written, because, AFAIK, there's no other way to implement the functionality otherwise.
I'm pretty sure that fairly low level tools such as Cython will have similar cases.
-- Marc-Andre Lemburg eGenix.com
Professional Python Services directly from the Experts (#1, Jun 14 2022)
Python Projects, Coaching and Support ... https://www.egenix.com/ Python Product Development ... https://consulting.egenix.com/
::: We implement business ideas - efficiently in both time and costs :::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 https://www.egenix.com/company/contact/ https://www.malemburg.com/