Skip to content

Commit

Permalink
gh-108278: Deprecate passing the three first params as keyword args f…
Browse files Browse the repository at this point in the history
…or 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.
  • Loading branch information
erlend-aasland committed Aug 28, 2023
1 parent bc5356b commit 4116592
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 6 deletions.
10 changes: 10 additions & 0 deletions Doc/library/sqlite3.rst
Expand Up @@ -763,6 +763,11 @@ Connection objects
... print(row)
('acbd18db4cc2f85cedef654fccc4a4d8',)

.. 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)

Expand Down Expand Up @@ -817,6 +822,11 @@ 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
11 changes: 10 additions & 1 deletion Doc/whatsnew/3.13.rst
Expand Up @@ -252,7 +252,16 @@ Deprecated
* 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`.)

Deprecate passing name, number of arguments, and the callable as keyword
arguments, for the following :class:`sqlite3.Connection` APIs:

* :meth:`~sqlite3.Connection.create_function`
* :meth:`~sqlite3.Connection.create_aggregate`

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

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

Pending Removal in Python 3.14
------------------------------
Expand Down
23 changes: 23 additions & 0 deletions Lib/test/test_sqlite3/test_userfunctions.py
Expand Up @@ -421,6 +421,29 @@ def test_func_return_illegal_value(self):
self.assertRaisesRegex(sqlite.OperationalError, msg,
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__)


class WindowSumInt:
def __init__(self):
Expand Down
@@ -0,0 +1,9 @@
Deprecate passing name, number of arguments, and the callable as keyword
arguments, for the following :class:`sqlite3.Connection` APIs:

* :meth:`~sqlite3.Connection.create_function`
* :meth:`~sqlite3.Connection.create_aggregate`

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

Patch by Erlend E. Aasland.
59 changes: 56 additions & 3 deletions Modules/_sqlite/clinic/connection.c.h

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

6 changes: 4 additions & 2 deletions Modules/_sqlite/connection.c
Expand Up @@ -1139,6 +1139,7 @@ _sqlite3.Connection.create_function as pysqlite_connection_create_function
name: str
narg: int
func: object
/ [from 3.15]
*
deterministic: bool = False
Expand All @@ -1150,7 +1151,7 @@ pysqlite_connection_create_function_impl(pysqlite_Connection *self,
PyTypeObject *cls, const char *name,
int narg, PyObject *func,
int deterministic)
/*[clinic end generated code: output=8a811529287ad240 input=b3e8e1d8ddaffbef]*/
/*[clinic end generated code: output=8a811529287ad240 input=c7c313b0ca8b519e]*/
{
int rc;
int flags = SQLITE_UTF8;
Expand Down Expand Up @@ -1341,6 +1342,7 @@ _sqlite3.Connection.create_aggregate as pysqlite_connection_create_aggregate
name: str
n_arg: int
aggregate_class: object
/ [from 3.15]
Creates a new aggregate.
[clinic start generated code]*/
Expand All @@ -1350,7 +1352,7 @@ pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
PyTypeObject *cls,
const char *name, int n_arg,
PyObject *aggregate_class)
/*[clinic end generated code: output=1b02d0f0aec7ff96 input=68a2a26366d4c686]*/
/*[clinic end generated code: output=1b02d0f0aec7ff96 input=8087056db6eae1cf]*/
{
int rc;

Expand Down

0 comments on commit 4116592

Please sign in to comment.