Skip to content

Commit a2d9ce8

Browse files
committed
refactor: use the _PyDictView_New function in Python < 3.13
1 parent 7f02431 commit a2d9ce8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

include/pyshim.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ inline int _PyArg_CheckPositional(const char *name, Py_ssize_t nargs, Py_ssize_t
7979
* @see Modified from https://github.com/python/cpython/blob/v3.13.0rc1/Objects/dictobject.c#L5806-L5827
8080
*/
8181
inline PyObject *PyDictViewObject_new(PyObject *dict, PyTypeObject *type) {
82+
#if PY_VERSION_HEX < 0x030d0000 // Python version is lower than 3.13
83+
return _PyDictView_New(dict, type);
84+
#else
8285
_PyDictViewObject *dv;
8386
dv = PyObject_GC_New(_PyDictViewObject, type);
8487
if (dv == NULL)
@@ -87,6 +90,7 @@ inline PyObject *PyDictViewObject_new(PyObject *dict, PyTypeObject *type) {
8790
dv->dv_dict = (PyDictObject *)dict;
8891
PyObject_GC_Track(dv);
8992
return (PyObject *)dv;
93+
#endif
9094
}
9195

9296
#endif // #ifndef PythonMonkey_py_version_shim_

0 commit comments

Comments
 (0)