← 返回首页
gh-92547: Remove deprecated sqlite3 features by erlend-aasland · Pull Request #92548 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .h  (1) .py  (4) .rst  (2) All 4 file types selected Viewed files
Conversations
Failed to load comments. Retry
Loading
Jump to
Jump to file
Failed to load files. Retry
Loading
Diff view
Unified
Split
Hide whitespace
Apply and reload
Show whitespace
Diff view
Unified
Split
Hide whitespace
Apply and reload
9 changes: 9 additions & 0 deletions Doc/whatsnew/3.12.rst
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
======================

Expand Down
14 changes: 0 additions & 14 deletions Lib/sqlite3/__init__.py
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,3 @@
"""

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}'")
14 changes: 0 additions & 14 deletions Lib/sqlite3/dbapi2.py
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,6 @@ def convert_timestamp(val):

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)
9 changes: 0 additions & 9 deletions Lib/test/test_sqlite3/test_dbapi.py
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,6 @@ def test_extended_error_code_on_exception(self):
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")))
Expand Down
12 changes: 0 additions & 12 deletions Lib/test/test_sqlite3/test_factory.py
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,6 @@ def test_custom(self):
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()

Expand Down
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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.
42 changes: 1 addition & 41 deletions Modules/_sqlite/clinic/module.c.h
Show comments View file Edit file Delete file Open in desktop
Load diff

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 0 additions & 31 deletions Modules/_sqlite/module.c
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}
Expand Down
Toggle all file notes Toggle all file annotations

Footer

© 2026 GitHub, Inc.