Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
52 changes: 21 additions & 31 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ Reference
Module functions
^^^^^^^^^^^^^^^^

.. function:: connect(database, timeout=5.0, detect_types=0, \
.. function:: connect(database, *, timeout=5.0, detect_types=0, \
isolation_level="DEFERRED", check_same_thread=True, \
factory=sqlite3.Connection, cached_statements=128, \
uri=False, *, \
uri=False, \
autocommit=sqlite3.LEGACY_TRANSACTION_CONTROL)

Open a connection to an SQLite database.
Expand Down Expand Up @@ -355,11 +355,8 @@ Module functions
.. versionchanged:: 3.12
Added 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.
.. versionchanged:: 3.15
All parameters except *database* are now keyword-only.

.. function:: complete_statement(statement)

Expand Down Expand Up @@ -693,7 +690,7 @@ Connection objects
:meth:`~Cursor.executescript` on it with the given *sql_script*.
Return the new cursor object.

.. method:: create_function(name, narg, func, *, deterministic=False)
.. method:: create_function(name, narg, func, /, *, deterministic=False)

Create or remove a user-defined SQL function.

Expand All @@ -719,6 +716,9 @@ Connection objects
.. versionchanged:: 3.8
Added the *deterministic* parameter.

.. versionchanged:: 3.15
The first three parameters are now positional-only.

Example:

.. doctest::
Expand All @@ -733,13 +733,8 @@ Connection objects
('acbd18db4cc2f85cedef654fccc4a4d8',)
>>> con.close()

.. versionchanged:: 3.13

Passing *name*, *narg*, and *func* as keyword arguments is deprecated.
These parameters will become positional-only in Python 3.15.


.. method:: create_aggregate(name, n_arg, aggregate_class)
.. method:: create_aggregate(name, n_arg, aggregate_class, /)

Create or remove a user-defined SQL aggregate function.

Expand All @@ -763,6 +758,9 @@ Connection objects
Set to ``None`` to remove an existing SQL aggregate function.
:type aggregate_class: :term:`class` | None

.. versionchanged:: 3.15
All three parameters are now positional-only.

Example:

.. testcode::
Expand Down Expand Up @@ -792,11 +790,6 @@ Connection objects

3

.. versionchanged:: 3.13

Passing *name*, *n_arg*, and *aggregate_class* as keyword arguments is deprecated.
These parameters will become positional-only in Python 3.15.


.. method:: create_window_function(name, num_params, aggregate_class, /)

Expand Down Expand Up @@ -937,7 +930,7 @@ Connection objects
Aborted queries will raise an :exc:`OperationalError`.


.. method:: set_authorizer(authorizer_callback)
.. method:: set_authorizer(authorizer_callback, /)

Register :term:`callable` *authorizer_callback* to be invoked
for each attempt to access a column of a table in the database.
Expand All @@ -962,12 +955,11 @@ Connection objects
.. versionchanged:: 3.11
Added support for disabling the authorizer using ``None``.

.. versionchanged:: 3.13
Passing *authorizer_callback* as a keyword argument is deprecated.
The parameter will become positional-only in Python 3.15.
.. versionchanged:: 3.15
The only parameter is now positional-only.


.. method:: set_progress_handler(progress_handler, n)
.. method:: set_progress_handler(progress_handler, /, n)

Register :term:`callable` *progress_handler* to be invoked for every *n*
instructions of the SQLite virtual machine. This is useful if you want to
Expand All @@ -981,12 +973,11 @@ Connection objects
currently executing query and cause it to raise a :exc:`DatabaseError`
exception.

.. versionchanged:: 3.13
Passing *progress_handler* as a keyword argument is deprecated.
The parameter will become positional-only in Python 3.15.
.. versionchanged:: 3.15
The first parameter is now positional-only.


.. method:: set_trace_callback(trace_callback)
.. method:: set_trace_callback(trace_callback, /)

Register :term:`callable` *trace_callback* to be invoked
for each SQL statement that is actually executed by the SQLite backend.
Expand All @@ -1009,9 +1000,8 @@ Connection objects

.. versionadded:: 3.3

.. versionchanged:: 3.13
Passing *trace_callback* as a keyword argument is deprecated.
The parameter will become positional-only in Python 3.15.
.. versionchanged:: 3.15
The first parameter is now positional-only.


.. method:: enable_load_extension(enabled, /)
Expand Down
14 changes: 3 additions & 11 deletions Lib/test/test_sqlite3/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,17 +550,9 @@ def test_connection_config(self):
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:
cx = sqlite.connect(":memory:", 1.0)
cx.close()
self.assertEqual(cm.filename, __file__)
with self.assertRaisesRegex(TypeError,
'takes exactly 1 positional argument'):
sqlite.connect(":memory:", 1.0)

def test_connection_resource_warning(self):
with self.assertWarns(ResourceWarning):
Expand Down
15 changes: 3 additions & 12 deletions Lib/test/test_sqlite3/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,9 @@ class Factory(sqlite.Connection):
def __init__(self, *args, **kwargs):
super(Factory, self).__init__(*args, **kwargs)

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:
with memory_database(5.0, 0, None, True, Factory) as con:
self.assertIsNone(con.isolation_level)
self.assertIsInstance(con, Factory)
self.assertEqual(cm.filename, __file__)
with self.assertRaisesRegex(TypeError,
'takes exactly 1 positional argument'):
memory_database(5.0, 0, None, True, Factory)


class CursorFactoryTests(MemoryDatabaseMixin, unittest.TestCase):
Expand Down
22 changes: 4 additions & 18 deletions Lib/test/test_sqlite3/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,9 @@ def bad_progress():
""")

def test_progress_handler_keyword_args(self):
regex = (
r"Passing keyword argument 'progress_handler' to "
r"_sqlite3.Connection.set_progress_handler\(\) is deprecated. "
r"Parameter 'progress_handler' will become positional-only in "
r"Python 3.15."
)

with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
with self.assertRaisesRegex(TypeError,
'takes at least 1 positional argument'):
self.con.set_progress_handler(progress_handler=lambda: None, n=1)
self.assertEqual(cm.filename, __file__)


class TraceCallbackTests(MemoryDatabaseMixin, unittest.TestCase):
Expand Down Expand Up @@ -353,16 +346,9 @@ def test_trace_bad_handler(self):
cx.execute("select 1")

def test_trace_keyword_args(self):
regex = (
r"Passing keyword argument 'trace_callback' to "
r"_sqlite3.Connection.set_trace_callback\(\) is deprecated. "
r"Parameter 'trace_callback' will become positional-only in "
r"Python 3.15."
)

with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
with self.assertRaisesRegex(TypeError,
'takes exactly 1 positional argument'):
self.con.set_trace_callback(trace_callback=lambda: None)
self.assertEqual(cm.filename, __file__)


if __name__ == "__main__":
Expand Down
55 changes: 7 additions & 48 deletions Lib/test/test_sqlite3/test_userfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,27 +422,9 @@ def test_func_return_illegal_value(self):
self.con.execute, "select badreturn()")

def test_func_keyword_args(self):
regex = (
r"Passing keyword arguments 'name', 'narg' and 'func' to "
r"_sqlite3.Connection.create_function\(\) is deprecated. "
r"Parameters 'name', 'narg' and 'func' will become "
r"positional-only in Python 3.15."
)

def noop():
return None

with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
self.con.create_function("noop", 0, func=noop)
self.assertEqual(cm.filename, __file__)

with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
self.con.create_function("noop", narg=0, func=noop)
self.assertEqual(cm.filename, __file__)

with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
self.con.create_function(name="noop", narg=0, func=noop)
self.assertEqual(cm.filename, __file__)
with self.assertRaisesRegex(TypeError,
'takes exactly 3 positional arguments'):
self.con.create_function("noop", 0, func=lambda: None)


class WindowSumInt:
Expand Down Expand Up @@ -737,25 +719,9 @@ def test_aggr_text(self):
self.assertEqual(val, txt)

def test_agg_keyword_args(self):
regex = (
r"Passing keyword arguments 'name', 'n_arg' and 'aggregate_class' to "
r"_sqlite3.Connection.create_aggregate\(\) is deprecated. "
r"Parameters 'name', 'n_arg' and 'aggregate_class' will become "
r"positional-only in Python 3.15."
)

with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
with self.assertRaisesRegex(TypeError,
'takes exactly 3 positional arguments'):
self.con.create_aggregate("test", 1, aggregate_class=AggrText)
self.assertEqual(cm.filename, __file__)

with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
self.con.create_aggregate("test", n_arg=1, aggregate_class=AggrText)
self.assertEqual(cm.filename, __file__)

with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
self.con.create_aggregate(name="test", n_arg=0,
aggregate_class=AggrText)
self.assertEqual(cm.filename, __file__)


class AuthorizerTests(unittest.TestCase):
Expand Down Expand Up @@ -800,16 +766,9 @@ def test_clear_authorizer(self):
self.con.execute("select c2 from t1")

def test_authorizer_keyword_args(self):
regex = (
r"Passing keyword argument 'authorizer_callback' to "
r"_sqlite3.Connection.set_authorizer\(\) is deprecated. "
r"Parameter 'authorizer_callback' will become positional-only in "
r"Python 3.15."
)

with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
with self.assertRaisesRegex(TypeError,
'takes exactly 1 positional argument'):
self.con.set_authorizer(authorizer_callback=lambda: None)
self.assertEqual(cm.filename, __file__)


class AuthorizerRaiseExceptionTests(AuthorizerTests):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Clean up :class:`sqlite3.Connection` APIs. All parameters of
:func:`sqlite3.connect` except *database* are now keyword-only. The first
three parameters of methods :meth:`~sqlite3.Connection.create_function` and
:meth:`~sqlite3.Connection.create_aggregate` are now positional-only. The
first parameter of methods :meth:`~sqlite3.Connection.set_authorizer`,
:meth:`~sqlite3.Connection.set_progress_handler` and
:meth:`~sqlite3.Connection.set_trace_callback` is now positional-only.
14 changes: 4 additions & 10 deletions Modules/_sqlite/clinic/_sqlite3.connect.c.h

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

Loading
Loading