First, I’d like to thank you @vstinner and @steve.dower for your answers. Is it remarkable that a small question from a random guy get (so quickly) so interesting and informed answers. This is very much appreciated.
I’m going to add few remarks from my point of view of user of the scientific Python stack (and dev of few packages in this field, and Python teacher).
What would change my life in terms of Python usage would be to be able for applications needing some packages of the scientific Python stack to use PyPy and GraalPy (nearly) as easily as I use CPython today and to get the benefit in terms of speed of these alternative implementations even when extensions are used.
Currently,
- alternative Python implementations are very slow as soon as extensions are used (even a bit, like one poor Numpy float in pure Python code)
- Most projects do not upload wheels for PyPy and GraalPy (famous examples: Scipy and Pandas)
A proper solution to get a Python stack adapted for modern interpreters is clearly something like HPy. I write “something like HPy” since I don’t know if it should be HPy or an alternative project inspired by HPy. But I think the “universal wheels” of HPy are a key aspect that should be taken into account. Also gradual porting and better debugging. HPy has a lot of nice qualities.
Of course, the question of when this could be possible is important. It has strong practical implications if one can get that in something like 3 years or in something like 10 years. In 10 years, it is probable that Mojo will be properly open-source and quite mature. I take this example (Mojo) but I guess you see what I mean. Will it still be reasonable in few years to use Python for new scientific software projects needing performance? If Python users needing extensions have no other choice than using interpreters using or emulating the memory layout used in old CPython and ref counting, it might not be the case.
So it seems to me that we should try to find a fast path towards a Python stack adapted for modern interpreters.
The process that you describe seems really reasonable from the point of view of CPython (and thus the whole Python ecosystem) but it is also important that some projects (in particular Numpy) can go faster.
Of course, the changes in the CPython C API going in the direction of a C API adapted for modern interpreters seem very useful, especially if they can be used for older Python versions with pythoncapi-compat.
However, I’d like to point out that the current situation and plan of the C API working group introduce an uncertainty which does not help to start now an adaptation of some packages.
Let’s take the point of view of Numpy (which is really the key project to go towards a Python stack adapted for modern interpreters):
- Should we invest on HPy?
- Should we wait for another new CPython C API officially supported by the C API WG?
- Should we just slowly follow CPython using pythoncapi-compat?
It is even worth than that! Numpy 1 has been ported to HPy (at least nearly, I don’t know if all tests passed and there is also the question of the Numpy C API) but now the project is stalled for different reasons, but I guess in particular because of uncertainties about the direction to be taken regarding the Python C API. One could find some founding for such important and impactful tasks, but it is difficult if the direction is not clear.
It seems to me that to get “universal Numpy wheels” in few years, the C API WG should officially support HPy or something like HPy, i.e. a layer above the CPython C API that could be used now to port C extensions while supporting a reasonable range of Python versions. I realize that it is a very big thing and that it would need a specific PEP.
I’m going to finish by warning that all this is only a modest point of view of a Python user without experience of the CPython C API for anything serious!