From 8b169672a9294716f791cd4a8afc452b24a8ed84 Mon Sep 17 00:00:00 2001 From: Aviv Palivoda Date: Sat, 13 May 2017 19:33:14 +0300 Subject: [PATCH 1/6] Add deprecation warning for Cache object --- Modules/_sqlite/module.c | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c index db2b4958b1463e6..53705fd96c42690 100644 --- a/Modules/_sqlite/module.c +++ b/Modules/_sqlite/module.c @@ -330,6 +330,43 @@ static const IntConstantPair _int_constants[] = { }; +static PyObject *pysqlite_cache_deprecated_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +{ + pysqlite_Cache *self; + + /* print deprecation warning */ + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "Cache object has been deprecated", + 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 self; +} + +static void pysqlite_cache_deprecated_dealloc(PyObject* self) +{ + Py_TYPE(self)->tp_free((PyObject*)self); +} + +/* classes for statement and cache deprecation */ +static PyTypeObject pysqlite_CacheDeprecatedType = { + PyVarObject_HEAD_INIT(NULL, 0) + MODULE_NAME ".CacheDeprecated", /* tp_name */ + sizeof(pysqlite_CacheDeprecatedType), /* tp_basicsize */ + .tp_dealloc = (destructor)pysqlite_cache_deprecated_dealloc, + .tp_new = pysqlite_cache_deprecated_new, + .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, +}; + static struct PyModuleDef _sqlite3module = { PyModuleDef_HEAD_INIT, "_sqlite3", @@ -362,6 +399,8 @@ PyMODINIT_FUNC PyInit__sqlite3(void) return NULL; } + PyType_Ready(&pysqlite_CacheDeprecatedType); + Py_INCREF(&pysqlite_ConnectionType); PyModule_AddObject(module, "Connection", (PyObject*) &pysqlite_ConnectionType); Py_INCREF(&pysqlite_CursorType); @@ -369,7 +408,7 @@ PyMODINIT_FUNC PyInit__sqlite3(void) Py_INCREF(&pysqlite_CacheType); PyModule_AddObject(module, "Statement", (PyObject*)&pysqlite_StatementType); Py_INCREF(&pysqlite_StatementType); - PyModule_AddObject(module, "Cache", (PyObject*) &pysqlite_CacheType); + PyModule_AddObject(module, "Cache", (PyObject*) &pysqlite_CacheDeprecatedType); Py_INCREF(&pysqlite_PrepareProtocolType); PyModule_AddObject(module, "PrepareProtocol", (PyObject*) &pysqlite_PrepareProtocolType); Py_INCREF(&pysqlite_RowType); From c8aa9c00a63dee118de6fc8dbc324cc3c4db49ac Mon Sep 17 00:00:00 2001 From: Aviv Palivoda Date: Sat, 13 May 2017 19:48:36 +0300 Subject: [PATCH 2/6] Add deprecation warning for Statement --- Modules/_sqlite/module.c | 46 ++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c index 53705fd96c42690..4ef7f3615613679 100644 --- a/Modules/_sqlite/module.c +++ b/Modules/_sqlite/module.c @@ -349,24 +349,52 @@ static PyObject *pysqlite_cache_deprecated_new(PyTypeObject *type, PyObject *arg Py_TYPE(self)->tp_free((PyObject*)self); return NULL; } - return self; + return (PyObject *)self; } -static void pysqlite_cache_deprecated_dealloc(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; + + /* print deprecation warning */ + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "Statement object has been deprecated", + 1)) + return NULL; + + self = (pysqlite_Statement *) pysqlite_StatementType.tp_alloc(&pysqlite_StatementType, 0); + if (!self) { + return NULL; + } + + return (PyObject *)self; +} + /* classes for statement and cache deprecation */ static PyTypeObject pysqlite_CacheDeprecatedType = { PyVarObject_HEAD_INIT(NULL, 0) MODULE_NAME ".CacheDeprecated", /* tp_name */ sizeof(pysqlite_CacheDeprecatedType), /* tp_basicsize */ - .tp_dealloc = (destructor)pysqlite_cache_deprecated_dealloc, + .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", @@ -393,21 +421,21 @@ 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; } - PyType_Ready(&pysqlite_CacheDeprecatedType); - Py_INCREF(&pysqlite_ConnectionType); 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); + 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); From 430f2508663e8af3f41ba2d79b6315927c66b6ae Mon Sep 17 00:00:00 2001 From: Aviv Palivoda Date: Sat, 13 May 2017 19:56:50 +0300 Subject: [PATCH 3/6] Add tests for Cache and Statement deprecation --- Lib/sqlite3/test/regression.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py index 34cd233535dc164..597f314d32cb73d 100644 --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -397,6 +397,14 @@ def callback(*args): del ref support.gc_collect() + def CheckCacheDeprecationWarning(self): + with self.assertWarns(DeprecationWarning): + sqlite.Cache(int) + + def CheckStatementDeprecationWarning(self): + with self.assertWarns(DeprecationWarning): + sqlite.Statement() + def suite(): regression_suite = unittest.makeSuite(RegressionTests, "Check") From 765b21a6055da749858aba03df0f9dd5a494ebaf Mon Sep 17 00:00:00 2001 From: Aviv Palivoda Date: Mon, 8 Oct 2018 13:25:38 +0300 Subject: [PATCH 4/6] Add DeprecationTests --- Lib/sqlite3/test/regression.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py index 597f314d32cb73d..dac9c6785e575f1 100644 --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -397,6 +397,8 @@ def callback(*args): del ref support.gc_collect() + +class DeprecationTests(unittest.TestCase): def CheckCacheDeprecationWarning(self): with self.assertWarns(DeprecationWarning): sqlite.Cache(int) @@ -408,7 +410,8 @@ def CheckStatementDeprecationWarning(self): 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() From 4a109ed1cf72b1252a3d33d734d864d6adad7301 Mon Sep 17 00:00:00 2001 From: Aviv Palivoda Date: Mon, 8 Oct 2018 13:28:35 +0300 Subject: [PATCH 5/6] CR fixes --- Modules/_sqlite/module.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c index 4ef7f3615613679..e833728ffe98195 100644 --- a/Modules/_sqlite/module.c +++ b/Modules/_sqlite/module.c @@ -334,9 +334,8 @@ static PyObject *pysqlite_cache_deprecated_new(PyTypeObject *type, PyObject *arg { pysqlite_Cache *self; - /* print deprecation warning */ if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Cache object has been deprecated", + "Cache object has been deprecated, it won't be exposed in Python 3.9", 1)) return NULL; @@ -362,9 +361,8 @@ static PyObject *pysqlite_statement_deprecated_new(PyTypeObject *type, PyObject { pysqlite_Statement *self; - /* print deprecation warning */ if (PyErr_WarnEx(PyExc_DeprecationWarning, - "Statement object has been deprecated", + "Statement object has been deprecated, it won't be exposed in Python 3.9", 1)) return NULL; @@ -376,7 +374,7 @@ static PyObject *pysqlite_statement_deprecated_new(PyTypeObject *type, PyObject return (PyObject *)self; } -/* classes for statement and cache deprecation */ + static PyTypeObject pysqlite_CacheDeprecatedType = { PyVarObject_HEAD_INIT(NULL, 0) MODULE_NAME ".CacheDeprecated", /* tp_name */ @@ -434,7 +432,7 @@ PyMODINIT_FUNC PyInit__sqlite3(void) Py_INCREF(&pysqlite_CursorType); PyModule_AddObject(module, "Cursor", (PyObject*) &pysqlite_CursorType); Py_INCREF(&pysqlite_StatementDeprecatedType); - PyModule_AddObject(module, "Statement", (PyObject*)&pysqlite_StatementDeprecatedType); + PyModule_AddObject(module, "Statement", (PyObject*) &pysqlite_StatementDeprecatedType); Py_INCREF(&pysqlite_CacheDeprecatedType); PyModule_AddObject(module, "Cache", (PyObject*) &pysqlite_CacheDeprecatedType); Py_INCREF(&pysqlite_PrepareProtocolType); From b37d55c541fcb0df744553923fe114a160964072 Mon Sep 17 00:00:00 2001 From: Aviv Palivoda Date: Mon, 8 Oct 2018 13:57:34 +0300 Subject: [PATCH 6/6] Add NEWS entry --- Doc/whatsnew/3.8.rst | 3 +++ .../next/Library/2018-10-08-13-31-49.bpo-30262.g9P1x4.rst | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2018-10-08-13-31-49.bpo-30262.g9P1x4.rst diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index a146249178f40d7..a60e5bbeb94ec9e 100644 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -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 ======= diff --git a/Misc/NEWS.d/next/Library/2018-10-08-13-31-49.bpo-30262.g9P1x4.rst b/Misc/NEWS.d/next/Library/2018-10-08-13-31-49.bpo-30262.g9P1x4.rst new file mode 100644 index 000000000000000..1f17620252e897b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-10-08-13-31-49.bpo-30262.g9P1x4.rst @@ -0,0 +1,3 @@ + +Deprecate :mod:`sqlite3` ``Cache`` and ``Statement`` classes. +Patch by Aviv Palivoda