bpo-39573: Py_TYPE becomes a static inline function by vstinner · Pull Request #26493 · python/cpython (original) (raw)
One year ago, I already pushed the same change to Python 3.10, but it broke many projects and so had to be reverted, see: https://bugs.python.org/issue39573#msg370074
Multiple things changed since my latest attempt:
- Major projects like Cython and numpy have been prepared for this incompatible change
- I created the https://github.com/pythoncapi/pythoncapi_compat project which is made of two parts:
- pythoncapi_compat.h header file provides Py_SET_TYPE() and Py_SET_TYPE() to old Python versions: it supports Python 2.7-3.11.
- upgrade_pythoncapi.py script automates the migration of existing C extensions to the new API (Py_SET_TYPE, Py_SET_TYPE) without losing support with Python 2.7-3.8.
- pythoncapi_compat.h header and upgrade_pythoncapi.py script have been used successfully on multiple projects (bitarray, immutables, Mercurial, python-zstandard). These projects now include a copy of pythoncapi_compat.h to support old Python versions.
Note: C extensions implemented with Cython only have to regenerate the C files using Cython, if it's not already done (Cython was fixed one year ago).