]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-107938: Synchonise the signature of of sqlite3.connect and sqlite3.Connection...
authorErlend E. Aasland <erlend@python.org>
Mon, 14 Aug 2023 14:37:44 +0000 (16:37 +0200)
committerGitHub <noreply@github.com>
Mon, 14 Aug 2023 14:37:44 +0000 (16:37 +0200)
Modules/_sqlite/clinic/_sqlite3.connect.c.h [new file with mode: 0644]
Modules/_sqlite/connection.c
Modules/_sqlite/module.c

diff --git a/Modules/_sqlite/clinic/_sqlite3.connect.c.h b/Modules/_sqlite/clinic/_sqlite3.connect.c.h
new file mode 100644 (file)
index 0000000..0c4ebdf
--- /dev/null
@@ -0,0 +1,25 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+#  include "pycore_gc.h"            // PyGC_Head
+#  include "pycore_runtime.h"       // _Py_ID()
+#endif
+
+
+PyDoc_STRVAR(pysqlite_connect__doc__,
+"connect($module, /, database, timeout=5.0, detect_types=0,\n"
+"        isolation_level=\'\', check_same_thread=True,\n"
+"        factory=ConnectionType, cached_statements=128, uri=False, *,\n"
+"        autocommit=sqlite3.LEGACY_TRANSACTION_CONTROL)\n"
+"--\n"
+"\n"
+"Open a connection to the SQLite database file \'database\'.\n"
+"\n"
+"You can use \":memory:\" to open a database connection to a database that\n"
+"resides in RAM instead of on disk.");
+
+#define PYSQLITE_CONNECT_METHODDEF    \
+    {"connect", _PyCFunction_CAST(pysqlite_connect), METH_FASTCALL|METH_KEYWORDS, pysqlite_connect__doc__},
+/*[clinic end generated code: output=6a8458c9edf8fb7f input=a9049054013a1b77]*/
index ddd7ace81198bb0a33480fc01dc6edea37e1c6f3..3d2fcd3ae0788efb6225c2d9e9049a2030479f46 100644 (file)
@@ -212,7 +212,6 @@ class sqlite3_int64_converter(CConverter):
 [python start generated code]*/
 /*[python end generated code: output=da39a3ee5e6b4b0d input=dff8760fb1eba6a1]*/
 
-// NB: This needs to be in sync with the sqlite3.connect docstring
 /*[clinic input]
 _sqlite3.Connection.__init__ as pysqlite_connection_init
 
@@ -346,6 +345,34 @@ error:
     return -1;
 }
 
+/*[clinic input]
+# Create a new destination 'connect' for the docstring and methoddef only.
+# This makes it possible to keep the signatures for Connection.__init__ and
+# sqlite3.connect() synchronised.
+output push
+destination connect new file '{dirname}/clinic/_sqlite3.connect.c.h'
+
+# Only output the docstring and the PyMethodDef entry.
+output everything suppress
+output docstring_definition connect
+output methoddef_define connect
+
+# Define the sqlite3.connect function by cloning Connection.__init__.
+_sqlite3.connect as pysqlite_connect = _sqlite3.Connection.__init__
+
+Open a connection to the SQLite database file 'database'.
+
+You can use ":memory:" to open a database connection to a database that
+resides in RAM instead of on disk.
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=92260edff95d1720]*/
+
+/*[clinic input]
+# Restore normal Argument Clinic operation for the rest of this file.
+output pop
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b899ba9273edcce7]*/
+
 #define VISIT_CALLBACK_CONTEXT(ctx) \
 do {                                \
     if (ctx) {                      \
index 368e581b4f3355bd4469625a0cb3fa4634408f8a..0c503dfbebbd6c7b7cbcaf7f86a05f87c85f09da 100644 (file)
@@ -48,25 +48,16 @@ module _sqlite3
 [clinic start generated code]*/
 /*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/
 
-// NB: This needs to be in sync with the Connection.__init__ docstring.
-PyDoc_STRVAR(module_connect_doc,
-"connect($module, /, database, timeout=5.0, detect_types=0,\n"
-"        isolation_level='', check_same_thread=True,\n"
-"        factory=ConnectionType, cached_statements=128, uri=False, *,\n"
-"        autocommit=sqlite3.LEGACY_TRANSACTION_CONTROL)\n"
-"--\n"
-"\n"
-"Opens a connection to the SQLite database file database.\n"
-"\n"
-"You can use \":memory:\" to open a database connection to a database that resides\n"
-"in RAM instead of on disk.");
-
-#define PYSQLITE_CONNECT_METHODDEF    \
-    {"connect", _PyCFunction_CAST(module_connect), METH_FASTCALL|METH_KEYWORDS, module_connect_doc},
+/*
+ * We create 'clinic/_sqlite3.connect.c.h' in connection.c, in order to
+ * keep the signatures of sqlite3.Connection.__init__ and
+ * sqlite3.connect() synchronised.
+ */
+#include "clinic/_sqlite3.connect.c.h"
 
 static PyObject *
-module_connect(PyObject *module, PyObject *const *args, Py_ssize_t nargsf,
-               PyObject *kwnames)
+pysqlite_connect(PyObject *module, PyObject *const *args, Py_ssize_t nargsf,
+                 PyObject *kwnames)
 {
     pysqlite_state *state = pysqlite_get_state(module);
     PyObject *factory = (PyObject *)state->ConnectionType;