Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions Doc/whatsnew/3.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ Deprecated
versions. :class:`~ast.Constant` should be used instead.
(Contributed by Serhiy Storchaka in :issue:`32892`.)

* :mod:`sqlite3` classes ``Cache`` and ``Statement``
are considered deprecated and will be removed in future Python.
(Contributed by Aviv Palivoda in :issue:`30262`.)

Removed
=======
Expand Down
13 changes: 12 additions & 1 deletion Lib/sqlite3/test/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,20 @@ def callback(*args):
support.gc_collect()


class DeprecationTests(unittest.TestCase):
def CheckCacheDeprecationWarning(self):
Comment thread
palaviv marked this conversation as resolved.
with self.assertWarns(DeprecationWarning):
sqlite.Cache(int)

def CheckStatementDeprecationWarning(self):
with self.assertWarns(DeprecationWarning):
sqlite.Statement()


def suite():
regression_suite = unittest.makeSuite(RegressionTests, "Check")
return unittest.TestSuite((regression_suite,))
deprecation_suite = unittest.makeSuite(DeprecationTests, "Check")
return unittest.TestSuite((regression_suite, deprecation_suite))

def test():
runner = unittest.TextTestRunner()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

Deprecate :mod:`sqlite3` ``Cache`` and ``Statement`` classes.
Patch by Aviv Palivoda
75 changes: 70 additions & 5 deletions Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,69 @@ static const IntConstantPair _int_constants[] = {
};


static PyObject *pysqlite_cache_deprecated_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
pysqlite_Cache *self;

if (PyErr_WarnEx(PyExc_DeprecationWarning,
"Cache object has been deprecated, it won't be exposed in Python 3.9",
1))
return NULL;

self = (pysqlite_Cache *) pysqlite_CacheType.tp_alloc(&pysqlite_CacheType, 0);
if (!self) {
return NULL;
}

if (pysqlite_cache_init(self, args, kwargs) != 0) {
Py_TYPE(self)->tp_free((PyObject*)self);
return NULL;
}
return (PyObject *)self;
}

static void pysqlite_deprecated_dealloc(PyObject* self)
{
Py_TYPE(self)->tp_free((PyObject*)self);
}


static PyObject *pysqlite_statement_deprecated_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
pysqlite_Statement *self;

if (PyErr_WarnEx(PyExc_DeprecationWarning,
"Statement object has been deprecated, it won't be exposed in Python 3.9",
1))
return NULL;

self = (pysqlite_Statement *) pysqlite_StatementType.tp_alloc(&pysqlite_StatementType, 0);
if (!self) {
return NULL;
}

return (PyObject *)self;
}


static PyTypeObject pysqlite_CacheDeprecatedType = {
PyVarObject_HEAD_INIT(NULL, 0)
MODULE_NAME ".CacheDeprecated", /* tp_name */
sizeof(pysqlite_CacheDeprecatedType), /* tp_basicsize */
.tp_dealloc = (destructor)pysqlite_deprecated_dealloc,
.tp_new = pysqlite_cache_deprecated_new,
.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
};

static PyTypeObject pysqlite_StatementDeprecatedType = {
PyVarObject_HEAD_INIT(NULL, 0)
MODULE_NAME ".StatementDeprecated", /* tp_name */
sizeof(pysqlite_StatementDeprecatedType), /* tp_basicsize */
.tp_dealloc = (destructor)pysqlite_deprecated_dealloc,
.tp_new = pysqlite_statement_deprecated_new,
.tp_flags = Py_TPFLAGS_DEFAULT,
};

static struct PyModuleDef _sqlite3module = {
PyModuleDef_HEAD_INIT,
"_sqlite3",
Expand All @@ -356,7 +419,9 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
(pysqlite_connection_setup_types() < 0) ||
(pysqlite_cache_setup_types() < 0) ||
(pysqlite_statement_setup_types() < 0) ||
(pysqlite_prepare_protocol_setup_types() < 0)
(pysqlite_prepare_protocol_setup_types() < 0) ||
(PyType_Ready(&pysqlite_CacheDeprecatedType) < 0) ||
(PyType_Ready(&pysqlite_StatementDeprecatedType) < 0)
) {
Py_XDECREF(module);
return NULL;
Expand All @@ -366,10 +431,10 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
PyModule_AddObject(module, "Connection", (PyObject*) &pysqlite_ConnectionType);
Py_INCREF(&pysqlite_CursorType);
PyModule_AddObject(module, "Cursor", (PyObject*) &pysqlite_CursorType);
Py_INCREF(&pysqlite_CacheType);
PyModule_AddObject(module, "Statement", (PyObject*)&pysqlite_StatementType);
Py_INCREF(&pysqlite_StatementType);
PyModule_AddObject(module, "Cache", (PyObject*) &pysqlite_CacheType);
Py_INCREF(&pysqlite_StatementDeprecatedType);
PyModule_AddObject(module, "Statement", (PyObject*) &pysqlite_StatementDeprecatedType);
Py_INCREF(&pysqlite_CacheDeprecatedType);
PyModule_AddObject(module, "Cache", (PyObject*) &pysqlite_CacheDeprecatedType);
Py_INCREF(&pysqlite_PrepareProtocolType);
PyModule_AddObject(module, "PrepareProtocol", (PyObject*) &pysqlite_PrepareProtocolType);
Py_INCREF(&pysqlite_RowType);
Expand Down