From eb00e9070165ebee26c05b239f06ed7c03314e49 Mon Sep 17 00:00:00 2001 From: Elvis Pranskevichus Date: Tue, 13 Sep 2022 16:36:22 -0700 Subject: [PATCH] Add Py_GenericAlias Useful for extensions implementing generic container types, like `immutables` (see MagicStack/immutables#89). Co-Authored-By: ToBeReplaced --- pythoncapi_compat.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pythoncapi_compat.h b/pythoncapi_compat.h index d422996..05a58f7 100644 --- a/pythoncapi_compat.h +++ b/pythoncapi_compat.h @@ -428,6 +428,15 @@ _Py_IS_TYPE(PyObject *ob, PyTypeObject *type) { #define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST(ob), type) #endif +// bpo-39481 added Py_GenericAlias to Python 3.9.0a6. +#if PY_VERSION_HEX < 0x030900A6 && !defined(Py_GenericAlias) +PYCAPI_COMPAT_STATIC_INLINE(PyObject *) +Py_GenericAlias(PyObject *type, PyObject *item) +{ + Py_INCREF(type); + return type; +} +#endif // bpo-46906 added PyFloat_Pack2() and PyFloat_Unpack2() to Python 3.11a7. // bpo-11734 added _PyFloat_Pack2() and _PyFloat_Unpack2() to Python 3.6.0b1.