summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend@python.org>2023-08-15 08:09:56 (GMT)
committerGitHub <noreply@github.com>2023-08-15 08:09:56 (GMT)
commit13c36dc9ae5240124932137de4a94d81292c6c5f (patch)
treed0c519b57139c9af90bec3f6df794d37fdaf94b1 /Modules/_sqlite
parenta482e5bf0022f85424a6308529a9ad51f1bfbb71 (diff)
downloadcpython-13c36dc9ae5240124932137de4a94d81292c6c5f.zip
cpython-13c36dc9ae5240124932137de4a94d81292c6c5f.tar.gz
cpython-13c36dc9ae5240124932137de4a94d81292c6c5f.tar.bz2
gh-93057: Deprecate positional use of optional sqlite3.connect() params (#107948)
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r--Modules/_sqlite/clinic/_sqlite3.connect.c.h10
-rw-r--r--Modules/_sqlite/clinic/connection.c.h35
-rw-r--r--Modules/_sqlite/connection.c3
-rw-r--r--Modules/_sqlite/module.c11
4 files changed, 55 insertions, 4 deletions
diff --git a/Modules/_sqlite/clinic/_sqlite3.connect.c.h b/Modules/_sqlite/clinic/_sqlite3.connect.c.h
index 0c4ebdf..998c8de 100644
--- a/Modules/_sqlite/clinic/_sqlite3.connect.c.h
+++ b/Modules/_sqlite/clinic/_sqlite3.connect.c.h
@@ -18,8 +18,14 @@ PyDoc_STRVAR(pysqlite_connect__doc__,
"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.");
+"resides in RAM instead of on disk.\n"
+"\n"
+"Note: Passing more than 1 positional argument to _sqlite3.connect() is\n"
+"deprecated. Parameters \'timeout\', \'detect_types\', \'isolation_level\',\n"
+"\'check_same_thread\', \'factory\', \'cached_statements\' and \'uri\' will\n"
+"become keyword-only parameters in Python 3.15.\n"
+"");
#define PYSQLITE_CONNECT_METHODDEF \
{"connect", _PyCFunction_CAST(pysqlite_connect), METH_FASTCALL|METH_KEYWORDS, pysqlite_connect__doc__},
-/*[clinic end generated code: output=6a8458c9edf8fb7f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8d49736db880f09a input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/clinic/connection.c.h b/Modules/_sqlite/clinic/connection.c.h
index e869d7d..af98d61 100644
--- a/Modules/_sqlite/clinic/connection.c.h
+++ b/Modules/_sqlite/clinic/connection.c.h
@@ -59,6 +59,39 @@ pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
int uri = 0;
enum autocommit_mode autocommit = LEGACY_TRANSACTION_CONTROL;
+ // Emit compiler warnings when we get to Python 3.15.
+ #if PY_VERSION_HEX >= 0x030f00C0
+ # error \
+ "In connection.c, update parameter(s) 'timeout', 'detect_types', " \
+ "'isolation_level', 'check_same_thread', 'factory', " \
+ "'cached_statements' and 'uri' in the clinic input of " \
+ "'_sqlite3.Connection.__init__' to be keyword-only."
+ #elif PY_VERSION_HEX >= 0x030f00A0
+ # ifdef _MSC_VER
+ # pragma message ( \
+ "In connection.c, update parameter(s) 'timeout', 'detect_types', " \
+ "'isolation_level', 'check_same_thread', 'factory', " \
+ "'cached_statements' and 'uri' in the clinic input of " \
+ "'_sqlite3.Connection.__init__' to be keyword-only.")
+ # else
+ # warning \
+ "In connection.c, update parameter(s) 'timeout', 'detect_types', " \
+ "'isolation_level', 'check_same_thread', 'factory', " \
+ "'cached_statements' and 'uri' in the clinic input of " \
+ "'_sqlite3.Connection.__init__' to be keyword-only."
+ # endif
+ #endif
+ if (nargs > 1 && nargs <= 8) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "Passing more than 1 positional argument to _sqlite3.Connection()"
+ " is deprecated. Parameters 'timeout', 'detect_types', "
+ "'isolation_level', 'check_same_thread', 'factory', "
+ "'cached_statements' and 'uri' will become keyword-only "
+ "parameters in Python 3.15.", 1))
+ {
+ goto exit;
+ }
+ }
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 8, 0, argsbuf);
if (!fastargs) {
goto exit;
@@ -1659,4 +1692,4 @@ exit:
#ifndef DESERIALIZE_METHODDEF
#define DESERIALIZE_METHODDEF
#endif /* !defined(DESERIALIZE_METHODDEF) */
-/*[clinic end generated code: output=d3c6cb9326736ea5 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=5a05e5294ad9d2ce input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 3d2fcd3..0819acd 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -216,6 +216,7 @@ class sqlite3_int64_converter(CConverter):
_sqlite3.Connection.__init__ as pysqlite_connection_init
database: object
+ * [from 3.15]
timeout: double = 5.0
detect_types: int = 0
isolation_level: IsolationLevel = ""
@@ -234,7 +235,7 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
int check_same_thread, PyObject *factory,
int cache_size, int uri,
enum autocommit_mode autocommit)
-/*[clinic end generated code: output=cba057313ea7712f input=9b0ab6c12f674fa3]*/
+/*[clinic end generated code: output=cba057313ea7712f input=219c3dbecbae7d99]*/
{
if (PySys_Audit("sqlite3.connect", "O", database) < 0) {
return -1;
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
index 0c503df..dd45ffc 100644
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -64,6 +64,17 @@ pysqlite_connect(PyObject *module, PyObject *const *args, Py_ssize_t nargsf,
static const int FACTORY_POS = 5;
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ if (nargs > 1 && nargs <= 8) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "Passing more than 1 positional argument to sqlite3.connect()"
+ " is deprecated. Parameters 'timeout', 'detect_types', "
+ "'isolation_level', 'check_same_thread', 'factory', "
+ "'cached_statements' and 'uri' will become keyword-only "
+ "parameters in Python 3.15.", 1))
+ {
+ return NULL;
+ }
+ }
if (nargs > FACTORY_POS) {
factory = args[FACTORY_POS];
}