8000 gh-92547: Remove deprecated sqlite3 features (#92548) · python/cpython@00f22e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 00f22e8

Browse files
gh-92547: Remove deprecated sqlite3 features (#92548)
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>
1 parent 9b50585 commit 00f22e8

File tree

8 files changed

+16
-121
lines changed

8 files changed

+16
-121
lines changed

Doc/whatsnew/3.12.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ Deprecated
107107
Removed
108108
=======
109109

110+
* The following undocumented :mod:`sqlite3` features, deprecated in Python
111+
3.10, are now removed:
112+
113+
* ``sqlite3.enable_shared_cache()``
114+
* ``sqlite3.OptimizedUnicode``
115+
116+
(Contributed by Erlend E. Aasland in :gh:`92548`)
117+
118+
110119
Porting to Python 3.12
111120
======================
112121

Lib/sqlite3/__init__.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,3 @@
5555
"""
5656

5757
from sqlite3.dbapi2 import *
58-
59-
60-
# bpo-42264: OptimizedUnicode was deprecated in Python 3.10. It's scheduled
61-
# for removal in Python 3.12.
62-
def __getattr__(name):
63-
if name == "OptimizedUnicode":
64-
import warnings
65-
msg = ("""
66-
OptimizedUnicode is deprecated and will be removed in Python 3.12.
67-
Since Python 3.3 it has simply been an alias for 'str'.
68-
""")
69-
warnings.warn(msg, DeprecationWarning, stacklevel=2)
70-
return str
71-
raise AttributeError(f"module 'sqlite3' has no attribute '{name}'")

Lib/sqlite3/dbapi2.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,6 @@ def convert_timestamp(val):
8282

8383
register_adapters_and_converters()
8484

85-
# bpo-24464: enable_shared_cache was deprecated in Python 3.10. It's
86-
# scheduled for removal in Python 3.12.
87-
def enable_shared_cache(enable):
88-
from _sqlite3 import enable_shared_cache as _old_enable_shared_cache
89-
import warnings
90-
msg = (
91-
"enable_shared_cache is deprecated and will be removed in Python 3.12. "
92-
"Shared cache is strongly discouraged by the SQLite 3 documentation. "
93-
"If shared cache must be used, open the database in URI mode using"
94-
"the cache=shared query parameter."
95-
)
96-
warnings.warn(msg, DeprecationWarning, stacklevel=2)
97-
return _old_enable_shared_cache(enable)
98-
9985
# Clean up namespace
10086

10187
del(register_adapters_and_converters)

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,6 @@ def test_extended_error_code_on_exception(self):
344344
sqlite.SQLITE_CONSTRAINT_CHECK)
345345
self.assertEqual(exc.sqlite_errorname, "SQLITE_CONSTRAINT_CHECK")
346346

347-
# sqlite3_enable_shared_cache() is deprecated on macOS and calling it may raise
348-
# OperationalError on some buildbots.
349-
@unittest.skipIf(sys.platform == "darwin", "shared cache is deprecated on macOS")
350-
def test_shared_cache_deprecated(self):
351-
for enable in (True, False):
352-
with self.assertWarns(DeprecationWarning) as cm:
353-
sqlite.enable_shared_cache(enable)
354-
self.assertIn("dbapi.py", cm.filename)
355-
356347
def test_disallow_instantiation(self):
357348
cx = sqlite.connect(":memory:")
358349
check_disallow_instantiation(self, type(cx("select 1")))

Lib/test/test_sqlite3/test_factory.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,6 @@ def test_custom(self):
256256
self.assertEqual(type(row[0]), str, "type of row[0] must be unicode")
257257
self.assertTrue(row[0].endswith("reich"), "column must contain original data")
258258

259-
def test_optimized_unicode(self):
260-
# OptimizedUnicode is deprecated as of Python 3.10
261-
with self.assertWarns(DeprecationWarning) as cm:
262-
self.con.text_factory = sqlite.OptimizedUnicode
263-
self.assertIn("factory.py", cm.filename)
264-
austria = "Österreich"
265-
germany = "Deutchland"
266-
a_row = self.con.execute("select ?", (austria,)).fetchone()
267-
d_row = self.con.execute("select ?", (germany,)).fetchone()
268-
self.assertEqual(type(a_row[0]), str, "type of non-ASCII row must be str")
269-
self.assertEqual(type(d_row[0]), str, "type of ASCII-only row must be str")
270-
271259
def tearDown(self):
272260
self.con.close()
273261

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Remove undocumented :mod:`sqlite3` features deprecated in Python 3.10:
2+
3+
* ``sqlite3.enable_shared_cache()``
4+
* ``sqlite3.OptimizedUnicode``
5+
6+
Patch by Erlend E. Aasland.

Modules/_sqlite/clinic/module.c.h

Lines changed: 1 addition & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_sqlite/module.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -105,36 +105,6 @@ pysqlite_complete_statement_impl(PyObject *module, const char *statement)
105105
}
106106
}
107107

108-
/*[clinic input]
109-
_sqlite3.enable_shared_cache as pysqlite_enable_shared_cache
110-
111-
do_enable: int
112-
113-
Enable or disable shared cache mode for the calling thread.
114-
115-
This method is deprecated and will be removed in Python 3.12.
116-
Shared cache is strongly discouraged by the SQLite 3 documentation.
117-
If shared cache must be used, open the database in URI mode using
118-
the cache=shared query parameter.
119-
[clinic start generated code]*/
120-
121-
static PyObject *
122-
pysqlite_enable_shared_cache_impl(PyObject *module, int do_enable)
123-
/*[clinic end generated code: output=259c74eedee1516b input=26e40d5971d3487d]*/
124-
{
125-
int rc;
126-
127-
rc = sqlite3_enable_shared_cache(do_enable);
128-
129-
if (rc != SQLITE_OK) {
130-
pysqlite_state *state = pysqlite_get_state(module);
131-
PyErr_SetString(state->OperationalError, "Changing the shared_cache flag failed");
132-
return NULL;
133-
} else {
134-
Py_RETURN_NONE;
135-
}
136-
}
137-
138108
/*[clinic input]
139109
_sqlite3.register_adapter as pysqlite_register_adapter
140110
@@ -277,7 +247,6 @@ static PyMethodDef module_methods[] = {
277247
PYSQLITE_COMPLETE_STATEMENT_METHODDEF
278248
PYSQLITE_CONNECT_METHODDEF
279249
PYSQLITE_ENABLE_CALLBACK_TRACE_METHODDEF
280-
PYSQLITE_ENABLE_SHARED_CACHE_METHODDEF
281250
PYSQLITE_REGISTER_ADAPTER_METHODDEF
282251
PYSQLITE_REGISTER_CONVERTER_METHODDEF
283252
{NULL, NULL}

0 commit comments

Comments
 (0)
0