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-108278: Deprecate passing the first param of sqlite3.Connection callback APIs by keyword#108632

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 from1 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
NextNext commit
gh-108278: Deprecate passing the first param of sqlite3.Connection ca…
…llback APIs by keywordDeprecate passing the callback callable by keyword for the followingsqlite3.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.
  • Loading branch information
@erlend-aasland
erlend-aasland committedAug 29, 2023
commita207531b43f1e673ad3f1bb4585fc5a672599d07
27 changes: 21 additions & 6 deletionsDoc/library/sqlite3.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -763,10 +763,10 @@ Connection objects
... print(row)
('acbd18db4cc2f85cedef654fccc4a4d8',)

.. versionchanged:: 3.13
.. versionchanged:: 3.13

Passing *name*, *narg*, and *func* as keyword arguments is deprecated.
These parameters will become positional-only in Python 3.15.
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)
Expand DownExpand Up@@ -822,10 +822,10 @@ Connection objects

3

.. versionchanged:: 3.13
.. 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.
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 DownExpand Up@@ -991,6 +991,11 @@ Connection objects
.. versionchanged:: 3.11
Added support for disabling the authorizer using ``None``.

.. versionchanged:: 3.13

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


.. method:: set_progress_handler(progress_handler, n)

Expand All@@ -1006,6 +1011,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 to is deprecated.
The parameter will become positional-only in Python 3.15.


.. method:: set_trace_callback(trace_callback)

Expand All@@ -1030,6 +1040,11 @@ Connection objects

.. versionadded:: 3.3

.. versionchanged:: 3.13

Passing *trace_callback* as a keyword argument to is deprecated.
The parameter will become positional-only in Python 3.15.


.. method:: enable_load_extension(enabled, /)

Expand Down
7 changes: 7 additions & 0 deletionsDoc/whatsnew/3.13.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -266,6 +266,13 @@ Deprecated
* :meth:`~sqlite3.Connection.create_function`
* :meth:`~sqlite3.Connection.create_aggregate`

Deprecate passing the callback callable by keyword for the following
:class:`sqlite3.Connection` APIs:

* :meth:`~sqlite3.Connection.set_authorizer`
* :meth:`~sqlite3.Connection.set_progress_handler`
* :meth:`~sqlite3.Connection.set_trace_callback`

The affected parameters will become positional-only in Python 3.15.

(Contributed by Erlend E. Aasland in :gh:`107948` and :gh:`108278`.)
Expand Down
24 changes: 24 additions & 0 deletionsLib/test/test_sqlite3/test_hooks.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -219,6 +219,18 @@ def bad_progress():
create table foo(a, b)
""")

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:
self.con.set_progress_handler(progress_handler=lambda: None, n=1)
self.assertEqual(cm.filename, __file__)


class TraceCallbackTests(MemoryDatabaseMixin, unittest.TestCase):

Expand DownExpand Up@@ -340,6 +352,18 @@ def test_trace_bad_handler(self):
cx.set_trace_callback(lambda stmt: 5/0)
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:
self.con.set_trace_callback(trace_callback=lambda: None)
self.assertEqual(cm.filename, __file__)


if __name__ == "__main__":
unittest.main()
33 changes: 33 additions & 0 deletionsLib/test/test_sqlite3/test_userfunctions.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -737,6 +737,27 @@ def test_aggr_text(self):
val = cur.fetchone()[0]
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:
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):
@staticmethod
Expand DownExpand Up@@ -779,6 +800,18 @@ def test_clear_authorizer(self):
self.con.execute("select * from t2")
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:
self.con.set_authorizer(authorizer_callback=lambda: None)
self.assertEqual(cm.filename, __file__)


class AuthorizerRaiseExceptionTests(AuthorizerTests):
@staticmethod
Expand Down
92 changes: 85 additions & 7 deletionsModules/_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.

Loading

[8]ページ先頭

©2009-2025 Movatter.jp