Skip to content

Commit

Permalink
pythongh-108278: Deprecate passing the three first params as keyword …
Browse files Browse the repository at this point in the history
…args for sqlite3 UDF creation APIs (python#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 authored and vstinner committed Aug 28, 2023
1 parent bc5356b commit e4ede8e
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 12 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
15 changes: 14 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 Expand Up @@ -877,6 +886,10 @@ New Features
(with an underscore prefix).
(Contributed by Victor Stinner in :gh:`108014`.)

* Add :c:func:`PyMem_RawMalloc`, :c:func:`PyMem_RawCalloc`,
:c:func:`PyMem_RawRealloc` and :c:func:`PyMem_RawFree` to the limited C API.
(Contributed by Victor Stinner in :gh:`85283`.)

Porting to Python 3.13
----------------------

Expand Down
6 changes: 0 additions & 6 deletions Include/cpython/pymem.h
Expand Up @@ -2,12 +2,6 @@
# error "this header file must not be included directly"
#endif

PyAPI_FUNC(void *) PyMem_RawMalloc(size_t size);
PyAPI_FUNC(void *) PyMem_RawCalloc(size_t nelem, size_t elsize);
PyAPI_FUNC(void *) PyMem_RawRealloc(void *ptr, size_t new_size);
PyAPI_FUNC(void) PyMem_RawFree(void *ptr);


typedef enum {
/* PyMem_RawMalloc(), PyMem_RawRealloc() and PyMem_RawFree() */
PYMEM_DOMAIN_RAW,
Expand Down
6 changes: 6 additions & 0 deletions Include/pymem.h
Expand Up @@ -91,6 +91,12 @@ PyAPI_FUNC(void) PyMem_Free(void *ptr);
#define PyMem_DEL(p) PyMem_Free((p))


// Allocator which doesn't require the GIL to be held
PyAPI_FUNC(void *) PyMem_RawMalloc(size_t size);
PyAPI_FUNC(void *) PyMem_RawCalloc(size_t nelem, size_t elsize);
PyAPI_FUNC(void *) PyMem_RawRealloc(void *ptr, size_t new_size);
PyAPI_FUNC(void) PyMem_RawFree(void *ptr);

#ifndef Py_LIMITED_API
# define Py_CPYTHON_PYMEM_H
# include "cpython/pymem.h"
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,3 @@
Add :c:func:`PyMem_RawMalloc`, :c:func:`PyMem_RawCalloc`,
:c:func:`PyMem_RawRealloc` and :c:func:`PyMem_RawFree` to the limited C API.
Patch by Victor Stinner.
@@ -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 e4ede8e

Please sign in to comment.