diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2020-11-17 15:55:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-17 15:55:12 (GMT) |
commit | a1f401a58b213e400fbd8f0fa8dc5260a2389dab (patch) | |
tree | 8531d513ccfbe7479ffa0420d088af144d0603ac /Lib | |
parent | 296a796951032f678d063008f588ccc6958d0df1 (diff) | |
download | cpython-a1f401a58b213e400fbd8f0fa8dc5260a2389dab.zip cpython-a1f401a58b213e400fbd8f0fa8dc5260a2389dab.tar.gz cpython-a1f401a58b213e400fbd8f0fa8dc5260a2389dab.tar.bz2 |
bpo-42264: Deprecate sqlite3.OptimizedUnicode (GH-23163)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/sqlite3/__init__.py | 14 | ||||
-rw-r--r-- | Lib/sqlite3/test/factory.py | 7 |
2 files changed, 18 insertions, 3 deletions
diff --git a/Lib/sqlite3/__init__.py b/Lib/sqlite3/__init__.py index 6c91df2..f001c06 100644 --- a/Lib/sqlite3/__init__.py +++ b/Lib/sqlite3/__init__.py @@ -21,3 +21,17 @@ # 3. This notice may not be removed or altered from any source distribution. 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}'") diff --git a/Lib/sqlite3/test/factory.py b/Lib/sqlite3/test/factory.py index 95dd24b..d919973 100644 --- a/Lib/sqlite3/test/factory.py +++ b/Lib/sqlite3/test/factory.py @@ -254,9 +254,10 @@ class TextFactoryTests(unittest.TestCase): self.assertTrue(row[0].endswith("reich"), "column must contain original data") def CheckOptimizedUnicode(self): - # In py3k, str objects are always returned when text_factory - # is OptimizedUnicode - self.con.text_factory = sqlite.OptimizedUnicode + # 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() |