Skip to content

Commit 4116592

Browse files
gh-108278: Deprecate passing the three first params as keyword args for sqlite3 UDF creation APIs (#108281)
Deprecate passing name, number of arguments, and the callable as keyword arguments, for the following sqlite3.Connection APIs: - create_function(name, nargs, callable, ...) - create_aggregate(name, nargs, callable) The affected parameters will become positional-only in Python 3.15.
1 parent bc5356b commit 4116592

File tree

6 files changed

+112
-6
lines changed

6 files changed

+112
-6
lines changed

Doc/library/sqlite3.rst

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

766+
.. versionchanged:: 3.13
767+
768+
Passing *name*, *narg*, and *func* as keyword arguments is deprecated.
769+
These parameters will become positional-only in Python 3.15.
770+
766771

767772
.. method:: create_aggregate(name, n_arg, aggregate_class)
768773

@@ -817,6 +822,11 @@ Connection objects
817822

818823
3
819824

825+
.. versionchanged:: 3.13
826+
827+
Passing *name*, *n_arg*, and *aggregate_class* as keyword arguments is deprecated.
828+
These parameters will become positional-only in Python 3.15.
829+
820830

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

Doc/whatsnew/3.13.rst

+10-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,16 @@ Deprecated
252252
* Passing more than one positional argument to :func:`sqlite3.connect` and the
253253
:class:`sqlite3.Connection` constructor is deprecated. The remaining
254254
parameters will become keyword-only in Python 3.15.
255-
(Contributed by Erlend E. Aasland in :gh:`107948`.)
255+
256+
Deprecate passing name, number of arguments, and the callable as keyword
257+
arguments, for the following :class:`sqlite3.Connection` APIs:
258+
259+
* :meth:`~sqlite3.Connection.create_function`
260+
* :meth:`~sqlite3.Connection.create_aggregate`
261+
262+
The affected parameters will become positional-only in Python 3.15.
263+
264+
(Contributed by Erlend E. Aasland in :gh:`107948` and :gh:`108278`.)
256265

257266
Pending Removal in Python 3.14
258267
------------------------------

Lib/test/test_sqlite3/test_userfunctions.py

+23
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,29 @@ def test_func_return_illegal_value(self):
421421
self.assertRaisesRegex(sqlite.OperationalError, msg,
422422
self.con.execute, "select badreturn()")
423423

424+
def test_func_keyword_args(self):
425+
regex = (
426+
r"Passing keyword arguments 'name', 'narg' and 'func' to "
427+
r"_sqlite3.Connection.create_function\(\) is deprecated. "
428+
r"Parameters 'name', 'narg' and 'func' will become "
429+
r"positional-only in Python 3.15."
430+
)
431+
432+
def noop():
433+
return None
434+
435+
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
436+
self.con.create_function("noop", 0, func=noop)
437+
self.assertEqual(cm.filename, __file__)
438+
439+
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
440+
self.con.create_function("noop", narg=0, func=noop)
441+
self.assertEqual(cm.filename, __file__)
442+
443+
with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
444+
self.con.create_function(name="noop", narg=0, func=noop)
445+
self.assertEqual(cm.filename, __file__)
446+
424447

425448
class WindowSumInt:
426449
def __init__(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Deprecate passing name, number of arguments, and the callable as keyword
2+
arguments, for the following :class:`sqlite3.Connection` APIs:
3+
4+
* :meth:`~sqlite3.Connection.create_function`
5+
* :meth:`~sqlite3.Connection.create_aggregate`
6+
7+
The affected parameters will become positional-only in Python 3.15.
8+
9+
Patch by Erlend E. Aasland.

Modules/_sqlite/clinic/connection.c.h

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

Modules/_sqlite/connection.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,7 @@ _sqlite3.Connection.create_function as pysqlite_connection_create_function
11391139
name: str
11401140
narg: int
11411141
func: object
1142+
/ [from 3.15]
11421143
*
11431144
deterministic: bool = False
11441145
@@ -1150,7 +1151,7 @@ pysqlite_connection_create_function_impl(pysqlite_Connection *self,
11501151
PyTypeObject *cls, const char *name,
11511152
int narg, PyObject *func,
11521153
int deterministic)
1153-
/*[clinic end generated code: output=8a811529287ad240 input=b3e8e1d8ddaffbef]*/
1154+
/*[clinic end generated code: output=8a811529287ad240 input=c7c313b0ca8b519e]*/
11541155
{
11551156
int rc;
11561157
int flags = SQLITE_UTF8;
@@ -1341,6 +1342,7 @@ _sqlite3.Connection.create_aggregate as pysqlite_connection_create_aggregate
13411342
name: str
13421343
n_arg: int
13431344
aggregate_class: object
1345+
/ [from 3.15]
13441346
13451347
Creates a new aggregate.
13461348
[clinic start generated code]*/
@@ -1350,7 +1352,7 @@ pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
13501352
PyTypeObject *cls,
13511353
const char *name, int n_arg,
13521354
PyObject *aggregate_class)
1353-
/*[clinic end generated code: output=1b02d0f0aec7ff96 input=68a2a26366d4c686]*/
1355+
/*[clinic end generated code: output=1b02d0f0aec7ff96 input=8087056db6eae1cf]*/
13541356
{
13551357
int rc;
13561358

0 commit comments

Comments
 (0)