Skip to content

Commit a207531

Browse files
pythongh-108278: Deprecate passing the first param of sqlite3.Connection callback APIs by keyword
Deprecate passing the callback callable by keyword for the following sqlite3.Connection APIs: - set_authorizer(authorizer_callback) - set_progress_handler(progress_handler, ...) - set_trace_callback(trace_callback) The affected parameters will become positional-only in Python 3.15.
1 parent 6eaddc1 commit a207531

File tree

6 files changed

+179
-22
lines changed

6 files changed

+179
-22
lines changed

Doc/library/sqlite3.rst

+21-6
Original file line numberDiff line numberDiff line change
@@ -763,10 +763,10 @@ Connection objects
763763
... print(row)
764764
('acbd18db4cc2f85cedef654fccc4a4d8',)
765765

766-
.. versionchanged:: 3.13
766+
.. versionchanged:: 3.13
767767

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

771771

772772
.. method:: create_aggregate(name, n_arg, aggregate_class)
@@ -822,10 +822,10 @@ Connection objects
822822

823823
3
824824

825-
.. versionchanged:: 3.13
825+
.. versionchanged:: 3.13
826826

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

830830

831831
.. method:: create_window_function(name, num_params, aggregate_class, /)
@@ -991,6 +991,11 @@ Connection objects
991991
.. versionchanged:: 3.11
992992
Added support for disabling the authorizer using ``None``.
993993

994+
.. versionchanged:: 3.13
995+
996+
Passing *authorizer_callback* as a keyword argument to is deprecated.
997+
The parameter will become positional-only in Python 3.15.
998+
994999

9951000
.. method:: set_progress_handler(progress_handler, n)
9961001

@@ -1006,6 +1011,11 @@ Connection objects
10061011
currently executing query and cause it to raise a :exc:`DatabaseError`
10071012
exception.
10081013

1014+
.. versionchanged:: 3.13
1015+
1016+
Passing *progress_handler* as a keyword argument to is deprecated.
1017+
The parameter will become positional-only in Python 3.15.
1018+
10091019

10101020
.. method:: set_trace_callback(trace_callback)
10111021

@@ -1030,6 +1040,11 @@ Connection objects
10301040

10311041
.. versionadded:: 3.3
10321042

1043+
.. versionchanged:: 3.13
1044+
1045+
Passing *trace_callback* as a keyword argument to is deprecated.
1046+
The parameter will become positional-only in Python 3.15.
1047+
10331048

10341049
.. method:: enable_load_extension(enabled, /)
10351050

Doc/whatsnew/3.13.rst

+7
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,13 @@ Deprecated
266266
* :meth:`~sqlite3.Connection.create_function`
267267
* :meth:`~sqlite3.Connection.create_aggregate`
268268

269+
Deprecate passing the callback callable by keyword for the following
270+
:class:`sqlite3.Connection` APIs:
271+
272+
* :meth:`~sqlite3.Connection.set_authorizer`
273+
* :meth:`~sqlite3.Connection.set_progress_handler`
274+
* :meth:`~sqlite3.Connection.set_trace_callback`
275+
269276
The affected parameters will become positional-only in Python 3.15.
270277

271278
(Contributed by Erlend E. Aasland in :gh:`107948` and :gh:`108278`.)

Lib/test/test_sqlite3/test_hooks.py

+24
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ def bad_progress():
219219
create table foo(a, b)
220220
""")
221221

222+
def test_progress_handler_keyword_args(self):
223+
regex = (
224+
r"Passing keyword argument 'progress_handler' to "
225+
r"_sqlite3.Connection.set_progress_handler\(\) is deprecated. "
226+
r"Parameter 'progress_handler' will become positional-only in "
227+
r"Python 3.15."
228+
)
229+
230+
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
231+
self.con.set_progress_handler(progress_handler=lambda: None, n=1)
232+
self.assertEqual(cm.filename, __file__)
233+
222234

223235
class TraceCallbackTests(MemoryDatabaseMixin, unittest.TestCase):
224236

@@ -340,6 +352,18 @@ def test_trace_bad_handler(self):
340352
cx.set_trace_callback(lambda stmt: 5/0)
341353
cx.execute("select 1")
342354

355+
def test_trace_keyword_args(self):
356+
regex = (
357+
r"Passing keyword argument 'trace_callback' to "
358+
r"_sqlite3.Connection.set_trace_callback\(\) is deprecated. "
359+
r"Parameter 'trace_callback' will become positional-only in "
360+
r"Python 3.15."
361+
)
362+
363+
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
364+
self.con.set_trace_callback(trace_callback=lambda: None)
365+
self.assertEqual(cm.filename, __file__)
366+
343367

344368
if __name__ == "__main__":
345369
unittest.main()

Lib/test/test_sqlite3/test_userfunctions.py

+33
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,27 @@ def test_aggr_text(self):
737737
val = cur.fetchone()[0]
738738
self.assertEqual(val, txt)
739739

740+
def test_agg_keyword_args(self):
741+
regex = (
742+
r"Passing keyword arguments 'name', 'n_arg' and 'aggregate_class' to "
743+
r"_sqlite3.Connection.create_aggregate\(\) is deprecated. "
744+
r"Parameters 'name', 'n_arg' and 'aggregate_class' will become "
745+
r"positional-only in Python 3.15."
746+
)
747+
748+
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
749+
self.con.create_aggregate("test", 1, aggregate_class=AggrText)
750+
self.assertEqual(cm.filename, __file__)
751+
752+
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
753+
self.con.create_aggregate("test", n_arg=1, aggregate_class=AggrText)
754+
self.assertEqual(cm.filename, __file__)
755+
756+
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
757+
self.con.create_aggregate(name="test", n_arg=0,
758+
aggregate_class=AggrText)
759+
self.assertEqual(cm.filename, __file__)
760+
740761

741762
class AuthorizerTests(unittest.TestCase):
742763
@staticmethod
@@ -779,6 +800,18 @@ def test_clear_authorizer(self):
779800
self.con.execute("select * from t2")
780801
self.con.execute("select c2 from t1")
781802

803+
def test_authorizer_keyword_args(self):
804+
regex = (
805+
r"Passing keyword argument 'authorizer_callback' to "
806+
r"_sqlite3.Connection.set_authorizer\(\) is deprecated. "
807+
r"Parameter 'authorizer_callback' will become positional-only in "
808+
r"Python 3.15."
809+
)
810+
811+
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
812+
self.con.set_authorizer(authorizer_callback=lambda: None)
813+
self.assertEqual(cm.filename, __file__)
814+
782815

783816
class AuthorizerRaiseExceptionTests(AuthorizerTests):
784817
@staticmethod

Modules/_sqlite/clinic/connection.c.h

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

0 commit comments

Comments
 (0)