]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-92547: Remove deprecated sqlite3 features (#92548)
authorErlend Egeberg Aasland <erlend.aasland@protonmail.com>
Mon, 16 May 2022 17:52:08 +0000 (19:52 +0200)
committerGitHub <noreply@github.com>
Mon, 16 May 2022 17:52:08 +0000 (19:52 +0200)
The following sqlite3 features were deprecated in 3.10, scheduled for
removal in 3.12:

- sqlite3.OptimizedUnicode (gh-23163)
- sqlite3.enable_shared_cache (gh-24008)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Signed-off-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Doc/whatsnew/3.12.rst
Lib/sqlite3/__init__.py
Lib/sqlite3/dbapi2.py
Lib/test/test_sqlite3/test_dbapi.py
Lib/test/test_sqlite3/test_factory.py
Misc/NEWS.d/next/Library/2022-05-09-11-55-04.gh-issue-92547.CzVZft.rst [new file with mode: 0644]
Modules/_sqlite/clinic/module.c.h
Modules/_sqlite/module.c

index 70b26ba48cf627f0b409d6550dc0daa1ddaa79b1..033de1780b3d189d3a15964734c10ea7eeeace71 100644 (file)
@@ -107,6 +107,15 @@ Deprecated
 Removed
 =======
 
+* The following undocumented :mod:`sqlite3` features, deprecated in Python
+  3.10, are now removed:
+
+  * ``sqlite3.enable_shared_cache()``
+  * ``sqlite3.OptimizedUnicode``
+
+  (Contributed by Erlend E. Aasland in :gh:`92548`)
+
+
 Porting to Python 3.12
 ======================
 
index 5a2dbd360fb49f5189206f811d36543e5782ee16..34a9c047dd607c6f30bcf020857e29482adcf584 100644 (file)
@@ -55,17 +55,3 @@ The sqlite3 module is written by Gerhard Häring <gh@ghaering.de>.
 """
 
 from sqlite3.dbapi2 import *
-
-
-# bpo-42264: OptimizedUnicode was deprecated in Python 3.10.  It's scheduled
-# for removal in Python 3.12.
-def __getattr__(name):
-    if name == "OptimizedUnicode":
-        import warnings
-        msg = ("""
-            OptimizedUnicode is deprecated and will be removed in Python 3.12.
-            Since Python 3.3 it has simply been an alias for 'str'.
-        """)
-        warnings.warn(msg, DeprecationWarning, stacklevel=2)
-        return str
-    raise AttributeError(f"module 'sqlite3' has no attribute '{name}'")
index 7cf4dd32d541dd984d113d86559b20e02b84ff32..36ce769d5c6b3e4fbf231d07cd1b9bd4353cf0be 100644 (file)
@@ -82,20 +82,6 @@ def register_adapters_and_converters():
 
 register_adapters_and_converters()
 
-# bpo-24464: enable_shared_cache was deprecated in Python 3.10.  It's
-# scheduled for removal in Python 3.12.
-def enable_shared_cache(enable):
-    from _sqlite3 import enable_shared_cache as _old_enable_shared_cache
-    import warnings
-    msg = (
-        "enable_shared_cache is deprecated and will be removed in Python 3.12. "
-        "Shared cache is strongly discouraged by the SQLite 3 documentation. "
-        "If shared cache must be used, open the database in URI mode using"
-        "the cache=shared query parameter."
-    )
-    warnings.warn(msg, DeprecationWarning, stacklevel=2)
-    return _old_enable_shared_cache(enable)
-
 # Clean up namespace
 
 del(register_adapters_and_converters)
index e132fcdfb0e65803fbca1ae2d1c371c0e4fa598a..8a218973794db931d0a1ad020acf03f05960cd4b 100644 (file)
@@ -344,15 +344,6 @@ class ModuleTests(unittest.TestCase):
                              sqlite.SQLITE_CONSTRAINT_CHECK)
             self.assertEqual(exc.sqlite_errorname, "SQLITE_CONSTRAINT_CHECK")
 
-    # sqlite3_enable_shared_cache() is deprecated on macOS and calling it may raise
-    # OperationalError on some buildbots.
-    @unittest.skipIf(sys.platform == "darwin", "shared cache is deprecated on macOS")
-    def test_shared_cache_deprecated(self):
-        for enable in (True, False):
-            with self.assertWarns(DeprecationWarning) as cm:
-                sqlite.enable_shared_cache(enable)
-            self.assertIn("dbapi.py", cm.filename)
-
     def test_disallow_instantiation(self):
         cx = sqlite.connect(":memory:")
         check_disallow_instantiation(self, type(cx("select 1")))
index 420855ba34b602b04a204c095ed5891bd353a796..71603faa02840f8ec1b5d4c7f59075e0ab284b54 100644 (file)
@@ -256,18 +256,6 @@ class TextFactoryTests(unittest.TestCase):
         self.assertEqual(type(row[0]), str, "type of row[0] must be unicode")
         self.assertTrue(row[0].endswith("reich"), "column must contain original data")
 
-    def test_optimized_unicode(self):
-        # OptimizedUnicode is deprecated as of Python 3.10
-        with self.assertWarns(DeprecationWarning) as cm:
-            self.con.text_factory = sqlite.OptimizedUnicode
-        self.assertIn("factory.py", cm.filename)
-        austria = "Österreich"
-        germany = "Deutchland"
-        a_row = self.con.execute("select ?", (austria,)).fetchone()
-        d_row = self.con.execute("select ?", (germany,)).fetchone()
-        self.assertEqual(type(a_row[0]), str, "type of non-ASCII row must be str")
-        self.assertEqual(type(d_row[0]), str, "type of ASCII-only row must be str")
-
     def tearDown(self):
         self.con.close()
 
diff --git a/Misc/NEWS.d/next/Library/2022-05-09-11-55-04.gh-issue-92547.CzVZft.rst b/Misc/NEWS.d/next/Library/2022-05-09-11-55-04.gh-issue-92547.CzVZft.rst
new file mode 100644 (file)
index 0000000..5262697
--- /dev/null
@@ -0,0 +1,6 @@
+Remove undocumented :mod:`sqlite3` features deprecated in Python 3.10:
+
+* ``sqlite3.enable_shared_cache()``
+* ``sqlite3.OptimizedUnicode``
+
+Patch by Erlend E. Aasland.
index 8f7008adef2b1d5304ee390387150ba04c5399a2..74a6a362c05abae454f4092f9bce52eb20005757 100644 (file)
@@ -158,46 +158,6 @@ exit:
     return return_value;
 }
 
-PyDoc_STRVAR(pysqlite_enable_shared_cache__doc__,
-"enable_shared_cache($module, /, do_enable)\n"
-"--\n"
-"\n"
-"Enable or disable shared cache mode for the calling thread.\n"
-"\n"
-"This method is deprecated and will be removed in Python 3.12.\n"
-"Shared cache is strongly discouraged by the SQLite 3 documentation.\n"
-"If shared cache must be used, open the database in URI mode using\n"
-"the cache=shared query parameter.");
-
-#define PYSQLITE_ENABLE_SHARED_CACHE_METHODDEF    \
-    {"enable_shared_cache", _PyCFunction_CAST(pysqlite_enable_shared_cache), METH_FASTCALL|METH_KEYWORDS, pysqlite_enable_shared_cache__doc__},
-
-static PyObject *
-pysqlite_enable_shared_cache_impl(PyObject *module, int do_enable);
-
-static PyObject *
-pysqlite_enable_shared_cache(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
-{
-    PyObject *return_value = NULL;
-    static const char * const _keywords[] = {"do_enable", NULL};
-    static _PyArg_Parser _parser = {NULL, _keywords, "enable_shared_cache", 0};
-    PyObject *argsbuf[1];
-    int do_enable;
-
-    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
-    if (!args) {
-        goto exit;
-    }
-    do_enable = _PyLong_AsInt(args[0]);
-    if (do_enable == -1 && PyErr_Occurred()) {
-        goto exit;
-    }
-    return_value = pysqlite_enable_shared_cache_impl(module, do_enable);
-
-exit:
-    return return_value;
-}
-
 PyDoc_STRVAR(pysqlite_register_adapter__doc__,
 "register_adapter($module, type, caster, /)\n"
 "--\n"
@@ -334,4 +294,4 @@ skip_optional:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=d846459943008a9c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=43aa4f4356f9269d input=a9049054013a1b77]*/
index fbc57c7cc739eef132ec736fc6dd6f0b1f5bb397..78591f85c1f7deb9c9eaaf146a6b0a159af56192 100644 (file)
@@ -105,36 +105,6 @@ pysqlite_complete_statement_impl(PyObject *module, const char *statement)
     }
 }
 
-/*[clinic input]
-_sqlite3.enable_shared_cache as pysqlite_enable_shared_cache
-
-    do_enable: int
-
-Enable or disable shared cache mode for the calling thread.
-
-This method is deprecated and will be removed in Python 3.12.
-Shared cache is strongly discouraged by the SQLite 3 documentation.
-If shared cache must be used, open the database in URI mode using
-the cache=shared query parameter.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_enable_shared_cache_impl(PyObject *module, int do_enable)
-/*[clinic end generated code: output=259c74eedee1516b input=26e40d5971d3487d]*/
-{
-    int rc;
-
-    rc = sqlite3_enable_shared_cache(do_enable);
-
-    if (rc != SQLITE_OK) {
-        pysqlite_state *state = pysqlite_get_state(module);
-        PyErr_SetString(state->OperationalError, "Changing the shared_cache flag failed");
-        return NULL;
-    } else {
-        Py_RETURN_NONE;
-    }
-}
-
 /*[clinic input]
 _sqlite3.register_adapter as pysqlite_register_adapter
 
@@ -277,7 +247,6 @@ static PyMethodDef module_methods[] = {
     PYSQLITE_COMPLETE_STATEMENT_METHODDEF
     PYSQLITE_CONNECT_METHODDEF
     PYSQLITE_ENABLE_CALLBACK_TRACE_METHODDEF
-    PYSQLITE_ENABLE_SHARED_CACHE_METHODDEF
     PYSQLITE_REGISTER_ADAPTER_METHODDEF
     PYSQLITE_REGISTER_CONVERTER_METHODDEF
     {NULL, NULL}