Skip to content

Commit 1452a8a

Browse files
[3.11] pythongh-107938: Synchonise the signature of of sqlite3.connect and sqlite3.Connection.__init__ (python#107939)
(cherry picked from commit 6fbaba5)
1 parent e2420c5 commit 1452a8a

File tree

3 files changed

+61
-17
lines changed

3 files changed

+61
-17
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
@@ -158,7 +158,6 @@ class sqlite3_int64_converter(CConverter):
158158
[python start generated code]*/
159159
/*[python end generated code: output=da39a3ee5e6b4b0d input=e9bee126e0500e61]*/
160160

161-
// NB: This needs to be in sync with the sqlite3.connect docstring
162161
/*[clinic input]
163162
_sqlite3.Connection.__init__ as pysqlite_connection_init
164163
@@ -284,6 +283,34 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
284283
return -1;
285284
}
286285

286+
/*[clinic input]
287+
# Create a new destination 'connect' for the docstring and methoddef only.
288+
# This makes it possible to keep the signatures for Connection.__init__ and
289+
# sqlite3.connect() synchronised.
290+
output push
291+
destination connect new file '{dirname}/clinic/_sqlite3.connect.c.h'
292+
293+
# Only output the docstring and the PyMethodDef entry.
294+
output everything suppress
295+
output docstring_definition connect
296+
output methoddef_define connect
297+
298+
# Define the sqlite3.connect function by cloning Connection.__init__.
299+
_sqlite3.connect as pysqlite_connect = _sqlite3.Connection.__init__
300+
301+
Open a connection to the SQLite database file 'database'.
302+
303+
You can use ":memory:" to open a database connection to a database that
304+
resides in RAM instead of on disk.
305+
[clinic start generated code]*/
306+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=92260edff95d1720]*/
307+
308+
/*[clinic input]
309+
# Restore normal Argument Clinic operation for the rest of this file.
310+
output pop
311+
[clinic start generated code]*/
312+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b899ba9273edcce7]*/
313+
287314
#define VISIT_CALLBACK_CONTEXT(ctx) \
288315
do { \
289316
if (ctx) { \

Modules/_sqlite/module.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,16 @@ module _sqlite3
4242
[clinic start generated code]*/
4343
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/
4444

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

6052
static PyObject *
61-
module_connect(PyObject *module, PyObject *const *args, Py_ssize_t nargsf,
62-
PyObject *kwnames)
53+
pysqlite_connect(PyObject *module, PyObject *const *args, Py_ssize_t nargsf,
54+
PyObject *kwnames)
6355
{
6456
pysqlite_state *state = pysqlite_get_state(module);
6557
PyObject *factory = (PyObject *)state->ConnectionType;

0 commit comments

Comments
 (0)