I converted Py_TYPE() and Py_SIZE() macros to static inline functions in the future Python 3.11. It's a backward incompatible change. For example, "Py_TYPE(obj) = type;" must be replaced with "Py_SET_TYPE(obj, type);".
You can use the upgrade_pythoncapi.py script of my pythoncapi_compat project which does these changes for you: you just have to copy pythoncapi_compat.h to your project. This header file provides new C API functions like Py_NewRef() and Py_SET_TYPE() to old Python versions, Python 2.7-3.11.
I already converted Py_TYPE() and Py_SIZE() macros in Python 3.10, but it broke too many C extensions and so I had to revert the change. In the meanwhile, I updated many C extensions and created the pythoncapi_compat project. For example, Cython and numpy have been updated to use Py_SET_TYPE() and Py_SET_SIZE(). Mercurial and immutables projects now use pythoncapi_compat.
I'm interested by feedback on my pythoncapi_compat project ;-)
Tell me if you need help to update your project for Python 3.11 C API changes: https://docs.python.org/dev/whatsnew/3.11.html#c-api-changes
Night gathers, and now my watch begins. It shall not end until my death.