Skip to content

Commit 13c36dc

Browse files
gh-93057: Deprecate positional use of optional sqlite3.connect() params (#107948)
1 parent a482e5b commit 13c36dc

File tree

9 files changed

+92
-5
lines changed

9 files changed

+92
-5
lines changed

Doc/library/sqlite3.rst

+6
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@ Module functions
355355
.. versionadded:: 3.12
356356
The *autocommit* parameter.
357357

358+
.. versionchanged:: 3.13
359+
Positional use of the parameters *timeout*, *detect_types*,
360+
*isolation_level*, *check_same_thread*, *factory*, *cached_statements*,
361+
and *uri* is deprecated.
362+
They will become keyword-only parameters in Python 3.15.
363+
358364
.. function:: complete_statement(statement)
359365

360366
Return ``True`` if the string *statement* appears to contain

Doc/whatsnew/3.13.rst

+5
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ Deprecated
219219
They will be removed in Python 3.15.
220220
(Contributed by Victor Stinner in :gh:`105096`.)
221221

222+
* Passing more than one positional argument to :func:`sqlite3.connect` and the
223+
:class:`sqlite3.Connection` constructor is deprecated. The remaining
224+
parameters will become keyword-only in Python 3.15.
225+
(Contributed by Erlend E. Aasland in :gh:`107948`.)
226+
222227
Pending Removal in Python 3.14
223228
------------------------------
224229

Lib/test/test_sqlite3/test_dbapi.py

+13
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,19 @@ def test_connection_config(self):
582582
with self.assertRaisesRegex(sqlite.IntegrityError, "constraint"):
583583
cx.execute("insert into u values(0)")
584584

585+
def test_connect_positional_arguments(self):
586+
regex = (
587+
r"Passing more than 1 positional argument to sqlite3.connect\(\)"
588+
" is deprecated. Parameters 'timeout', 'detect_types', "
589+
"'isolation_level', 'check_same_thread', 'factory', "
590+
"'cached_statements' and 'uri' will become keyword-only "
591+
"parameters in Python 3.15."
592+
)
593+
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
594+
sqlite.connect(":memory:", 1.0)
595+
self.assertEqual(cm.filename, __file__)
596+
597+
585598

586599
class UninitialisedConnectionTests(unittest.TestCase):
587600
def setUp(self):

Lib/test/test_sqlite3/test_factory.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,16 @@ class Factory(sqlite.Connection):
6666
def __init__(self, *args, **kwargs):
6767
super(Factory, self).__init__(*args, **kwargs)
6868

69-
con = sqlite.connect(":memory:", 5.0, 0, None, True, Factory)
69+
regex = (
70+
r"Passing more than 1 positional argument to _sqlite3.Connection\(\) "
71+
r"is deprecated. Parameters 'timeout', 'detect_types', "
72+
r"'isolation_level', 'check_same_thread', 'factory', "
73+
r"'cached_statements' and 'uri' will become keyword-only "
74+
r"parameters in Python 3.15."
75+
)
76+
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
77+
con = sqlite.connect(":memory:", 5.0, 0, None, True, Factory)
78+
self.assertEqual(cm.filename, __file__)
7079
self.assertIsNone(con.isolation_level)
7180
self.assertIsInstance(con, Factory)
7281

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Passing more than one positional argument to :func:`sqlite3.connect` and the
2+
:class:`sqlite3.Connection` constructor is deprecated. The remaining parameters
3+
will become keyword-only in Python 3.15. Patch by Erlend E. Aasland.

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

+8-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_sqlite/clinic/connection.c.h

+34-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_sqlite/connection.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ class sqlite3_int64_converter(CConverter):
216216
_sqlite3.Connection.__init__ as pysqlite_connection_init
217217
218218
database: object
219+
* [from 3.15]
219220
timeout: double = 5.0
220221
detect_types: int = 0
221222
isolation_level: IsolationLevel = ""
@@ -234,7 +235,7 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
234235
int check_same_thread, PyObject *factory,
235236
int cache_size, int uri,
236237
enum autocommit_mode autocommit)
237-
/*[clinic end generated code: output=cba057313ea7712f input=9b0ab6c12f674fa3]*/
238+
/*[clinic end generated code: output=cba057313ea7712f input=219c3dbecbae7d99]*/
238239
{
239240
if (PySys_Audit("sqlite3.connect", "O", database) < 0) {
240241
return -1;

Modules/_sqlite/module.c

+11
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ pysqlite_connect(PyObject *module, PyObject *const *args, Py_ssize_t nargsf,
6464

6565
static const int FACTORY_POS = 5;
6666
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
67+
if (nargs > 1 && nargs <= 8) {
68+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
69+
"Passing more than 1 positional argument to sqlite3.connect()"
70+
" is deprecated. Parameters 'timeout', 'detect_types', "
71+
"'isolation_level', 'check_same_thread', 'factory', "
72+
"'cached_statements' and 'uri' will become keyword-only "
73+
"parameters in Python 3.15.", 1))
74+
{
75+
return NULL;
76+
}
77+
}
6778
if (nargs > FACTORY_POS) {
6879
factory = args[FACTORY_POS];
6980
}

0 commit comments

Comments
 (0)