]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
SQLAlchemy 1.4: Fix building the C extension on Python 3.13
authorBenjamin A. Beasley <code@musicinmybrain.net>
Thu, 20 Jun 2024 15:02:39 +0000 (11:02 -0400)
committerMichael Bayer <mike_mp@zzzcomputing.com>
Thu, 20 Jun 2024 17:39:02 +0000 (17:39 +0000)
Adjustments to the C extensions, which are specific to the SQLAlchemy 1.x
series, to work under Python 3.13.  Pull request courtesy Ben Beasley.

Fixes: #11499
Closes: #11500
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11500
Pull-request-sha: 8a5888b147022b4586d30dcd7159e4fa6a31ec0e

Change-Id: I1943eb387f9b075bf07e179f7a24762236e234bf

doc/build/changelog/unreleased_14/11499.rst [new file with mode: 0644]
lib/sqlalchemy/cextension/resultproxy.c

diff --git a/doc/build/changelog/unreleased_14/11499.rst b/doc/build/changelog/unreleased_14/11499.rst
new file mode 100644 (file)
index 0000000..e03062c
--- /dev/null
@@ -0,0 +1,6 @@
+.. change::
+    :tags: bug, engine
+    :tickets: 11499
+
+    Adjustments to the C extensions, which are specific to the SQLAlchemy 1.x
+    series, to work under Python 3.13.  Pull request courtesy Ben Beasley.
index 8e8b6f9e4feee5a5d8e52e98362b8706d55b2293..a88af0ede9662b7ac1fd6b1667084bff8fce82de 100644 (file)
@@ -821,6 +821,29 @@ typedef struct {
 
 static PyTypeObject tuplegetter_type;
 
+static int
+PyArg_NoKeywords(const char *funcname, PyObject *kwargs)
+{
+#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 13
+    /* Based on the one in CPython, removed from the public headers in 3.13
+     * (https://github.com/python/cpython/issues/110964)
+     */
+    if (kwargs == NULL)
+        return 1;
+    if (!PyDict_CheckExact(kwargs)) {
+        PyErr_BadInternalCall();
+        return 0;
+    }
+    if (PyDict_GET_SIZE(kwargs) == 0)
+        return 1;
+
+    PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments", funcname);
+    return 0;
+#else
+    return _PyArg_NoKeywords(funcname, kwargs);
+#endif
+}
+
 static PyObject *
 tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
@@ -828,7 +851,7 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
     PyObject *item;
     Py_ssize_t nitems;
 
-    if (!_PyArg_NoKeywords("tuplegetter", kwds))
+    if (!PyArg_NoKeywords("tuplegetter", kwds))
         return NULL;
 
     nitems = PyTuple_GET_SIZE(args);