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

gh-93057: Deprecate positional use of optional sqlite3.connect() params#107948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletionsDoc/library/sqlite3.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -355,6 +355,12 @@ Module functions
.. versionadded:: 3.12
The *autocommit* parameter.

.. versionchanged:: 3.13
Positional use of the parameters *timeout*, *detect_types*,
*isolation_level*, *check_same_thread*, *factory*, *cached_statements*,
and *uri* is deprecated.
They will become keyword-only parameters in Python 3.15.

.. function:: complete_statement(statement)

Return ``True`` if the string *statement* appears to contain
Expand Down
5 changes: 5 additions & 0 deletionsDoc/whatsnew/3.13.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -219,6 +219,11 @@ Deprecated
They will be removed in Python 3.15.
(Contributed by Victor Stinner in :gh:`105096`.)

* Passing more than one positional argument to :func:`sqlite3.connect` and the
:class:`sqlite3.Connection` constructor is deprecated. The remaining
parameters will become keyword-only in Python 3.15.
(Contributed by Erlend E. Aasland in :gh:`107948`.)

Pending Removal in Python 3.14
------------------------------

Expand Down
13 changes: 13 additions & 0 deletionsLib/test/test_sqlite3/test_dbapi.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -582,6 +582,19 @@ def test_connection_config(self):
with self.assertRaisesRegex(sqlite.IntegrityError, "constraint"):
cx.execute("insert into u values(0)")

def test_connect_positional_arguments(self):
regex = (
r"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."
)
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
sqlite.connect(":memory:", 1.0)
self.assertEqual(cm.filename, __file__)



class UninitialisedConnectionTests(unittest.TestCase):
def setUp(self):
Expand Down
11 changes: 10 additions & 1 deletionLib/test/test_sqlite3/test_factory.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -66,7 +66,16 @@ class Factory(sqlite.Connection):
def __init__(self, *args, **kwargs):
super(Factory, self).__init__(*args, **kwargs)

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

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
Passing more than one positional argument to :func:`sqlite3.connect` and the
:class:`sqlite3.Connection` constructor is deprecated. The remaining parameters
will become keyword-only in Python 3.15. Patch by Erlend E. Aasland.
10 changes: 8 additions & 2 deletionsModules/_sqlite/clinic/_sqlite3.connect.c.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

35 changes: 34 additions & 1 deletionModules/_sqlite/clinic/connection.c.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

3 changes: 2 additions & 1 deletionModules/_sqlite/connection.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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 = ""
Expand All@@ -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;
Expand Down
11 changes: 11 additions & 0 deletionsModules/_sqlite/module.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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];
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp