Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit13c36dc

Browse files
gh-93057: Deprecate positional use of optional sqlite3.connect() params (#107948)
1 parenta482e5b commit13c36dc

File tree

9 files changed

+92
-5
lines changed

9 files changed

+92
-5
lines changed

‎Doc/library/sqlite3.rst

Lines changed: 6 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

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

585+
deftest_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+
withself.assertWarnsRegex(DeprecationWarning,regex)ascm:
594+
sqlite.connect(":memory:",1.0)
595+
self.assertEqual(cm.filename,__file__)
596+
597+
585598

586599
classUninitialisedConnectionTests(unittest.TestCase):
587600
defsetUp(self):

‎Lib/test/test_sqlite3/test_factory.py

Lines changed: 10 additions & 1 deletion
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+
withself.assertWarnsRegex(DeprecationWarning,regex)ascm:
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Modules/_sqlite/clinic/connection.c.h

Lines changed: 34 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Modules/_sqlite/connection.c

Lines changed: 2 additions & 1 deletion
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
intcheck_same_thread,PyObject*factory,
235236
intcache_size,inturi,
236237
enumautocommit_modeautocommit)
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

Lines changed: 11 additions & 0 deletions
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
staticconstintFACTORY_POS=5;
6666
Py_ssize_tnargs=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+
returnNULL;
76+
}
77+
}
6778
if (nargs>FACTORY_POS) {
6879
factory=args[FACTORY_POS];
6980
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp