Skip to content

Commit 6fbaba5

Browse files
gh-107938: Synchonise the signature of of sqlite3.connect and sqlite3.Connection.__init__ (#107939)
1 parent 608927b commit 6fbaba5

File tree

3 files changed

+61
-18
lines changed

3 files changed

+61
-18
lines changed

Modules/_sqlite/clinic/_sqlite3.connect.c.h

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_sqlite/connection.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ class sqlite3_int64_converter(CConverter):
212212
[python start generated code]*/
213213
/*[python end generated code: output=da39a3ee5e6b4b0d input=dff8760fb1eba6a1]*/
214214

215-
// NB: This needs to be in sync with the sqlite3.connect docstring
216215
/*[clinic input]
217216
_sqlite3.Connection.__init__ as pysqlite_connection_init
218217
@@ -346,6 +345,34 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
346345
return -1;
347346
}
348347

348+
/*[clinic input]
349+
# Create a new destination 'connect' for the docstring and methoddef only.
350+
# This makes it possible to keep the signatures for Connection.__init__ and
351+
# sqlite3.connect() synchronised.
352+
output push
353+
destination connect new file '{dirname}/clinic/_sqlite3.connect.c.h'
354+
355+
# Only output the docstring and the PyMethodDef entry.
356+
output everything suppress
357+
output docstring_definition connect
358+
output methoddef_define connect
359+
360+
# Define the sqlite3.connect function by cloning Connection.__init__.
361+
_sqlite3.connect as pysqlite_connect = _sqlite3.Connection.__init__
362+
363+
Open a connection to the SQLite database file 'database'.
364+
365+
You can use ":memory:" to open a database connection to a database that
366+
resides in RAM instead of on disk.
367+
[clinic start generated code]*/
368+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=92260edff95d1720]*/
369+
370+
/*[clinic input]
371+
# Restore normal Argument Clinic operation for the rest of this file.
372+
output pop
373+
[clinic start generated code]*/
374+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b899ba9273edcce7]*/
375+
349376
#define VISIT_CALLBACK_CONTEXT(ctx) \
350377
do { \
351378
if (ctx) { \

Modules/_sqlite/module.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,16 @@ module _sqlite3
4848
[clinic start generated code]*/
4949
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/
5050

51-
// NB: This needs to be in sync with the Connection.__init__ docstring.
52-
PyDoc_STRVAR(module_connect_doc,
53-
"connect($module, /, database, timeout=5.0, detect_types=0,\n"
54-
" isolation_level='', check_same_thread=True,\n"
55-
" factory=ConnectionType, cached_statements=128, uri=False, *,\n"
56-
" autocommit=sqlite3.LEGACY_TRANSACTION_CONTROL)\n"
57-
"--\n"
58-
"\n"
59-
"Opens a connection to the SQLite database file database.\n"
60-
"\n"
61-
"You can use \":memory:\" to open a database connection to a database that resides\n"
62-
"in RAM instead of on disk.");
63-
64-
#define PYSQLITE_CONNECT_METHODDEF \
65-
{"connect", _PyCFunction_CAST(module_connect), METH_FASTCALL|METH_KEYWORDS, module_connect_doc},
51+
/*
52+
* We create 'clinic/_sqlite3.connect.c.h' in connection.c, in order to
53+
* keep the signatures of sqlite3.Connection.__init__ and
54+
* sqlite3.connect() synchronised.
55+
*/
56+
#include "clinic/_sqlite3.connect.c.h"
6657

6758
static PyObject *
68-
module_connect(PyObject *module, PyObject *const *args, Py_ssize_t nargsf,
69-
PyObject *kwnames)
59+
pysqlite_connect(PyObject *module, PyObject *const *args, Py_ssize_t nargsf,
60+
PyObject *kwnames)
7061
{
7162
pysqlite_state *state = pysqlite_get_state(module);
7263
PyObject *factory = (PyObject *)state->ConnectionType;

0 commit comments

Comments
 (0)