]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-93370: Deprecate sqlite3.version and sqlite3.version_info (#93482)
authorKalyan <kalyan.ben10@live.com>
Tue, 7 Jun 2022 23:34:50 +0000 (05:04 +0530)
committerGitHub <noreply@github.com>
Tue, 7 Jun 2022 23:34:50 +0000 (01:34 +0200)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Doc/library/sqlite3.rst
Lib/sqlite3/__init__.py
Lib/sqlite3/dbapi2.py
Lib/test/test_sqlite3/test_dbapi.py
Misc/ACKS
Misc/NEWS.d/next/Library/2022-06-03-22-13-28.gh-issue-93370.tjfu9L.rst [new file with mode: 0644]
Modules/_sqlite/module.c

index 5c62047a4218957d12730ffef12e489fefc42e7f..140cd94c408d04dbb7e81f4104041393ea0d3c25 100644 (file)
@@ -142,12 +142,22 @@ Module functions and constants
    The version number of this module, as a string. This is not the version of
    the SQLite library.
 
+   .. deprecated-removed:: 3.12 3.14
+      This constant used to reflect the version number of the ``pysqlite``
+      package, a third-party library which used to upstream changes to
+      ``sqlite3``. Today, it carries no meaning or practical value.
+
 
 .. data:: version_info
 
    The version number of this module, as a tuple of integers. This is not the
    version of the SQLite library.
 
+   .. deprecated-removed:: 3.12 3.14
+      This constant used to reflect the version number of the ``pysqlite``
+      package, a third-party library which used to upstream changes to
+      ``sqlite3``. Today, it carries no meaning or practical value.
+
 
 .. data:: sqlite_version
 
index 34a9c047dd607c6f30bcf020857e29482adcf584..927267cf0b92ff6a6eb370e7891d7452b0c6cb60 100644 (file)
@@ -55,3 +55,16 @@ The sqlite3 module is written by Gerhard Häring <gh@ghaering.de>.
 """
 
 from sqlite3.dbapi2 import *
+from sqlite3.dbapi2 import (_deprecated_names,
+                            _deprecated_version_info,
+                            _deprecated_version)
+
+
+def __getattr__(name):
+    if name in _deprecated_names:
+        from warnings import warn
+
+        warn(f"{name} is deprecated and will be removed in Python 3.14",
+             DeprecationWarning, stacklevel=2)
+        return globals()[f"_deprecated_{name}"]
+    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
index 36ce769d5c6b3e4fbf231d07cd1b9bd4353cf0be..3b6d2f7ba2d5956a75414fe1ef695d8ee6cc17ef 100644 (file)
@@ -25,6 +25,9 @@ import time
 import collections.abc
 
 from _sqlite3 import *
+from _sqlite3 import _deprecated_version
+
+_deprecated_names = frozenset({"version", "version_info"})
 
 paramstyle = "qmark"
 
@@ -45,7 +48,7 @@ def TimeFromTicks(ticks):
 def TimestampFromTicks(ticks):
     return Timestamp(*time.localtime(ticks)[:6])
 
-version_info = tuple([int(x) for x in version.split(".")])
+_deprecated_version_info = tuple(map(int, _deprecated_version.split(".")))
 sqlite_version_info = tuple([int(x) for x in sqlite_version.split(".")])
 
 Binary = memoryview
@@ -85,3 +88,12 @@ register_adapters_and_converters()
 # Clean up namespace
 
 del(register_adapters_and_converters)
+
+def __getattr__(name):
+    if name in _deprecated_names:
+        from warnings import warn
+
+        warn(f"{name} is deprecated and will be removed in Python 3.14",
+             DeprecationWarning, stacklevel=2)
+        return globals()[f"_deprecated_{name}"]
+    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
index 1fa02db3b3af4127792654da7928902c2abd6356..b958bf112a93095c539729ba689e344ec4f98376 100644 (file)
@@ -57,6 +57,17 @@ class ModuleTests(unittest.TestCase):
         self.assertEqual(sqlite.apilevel, "2.0",
                          "apilevel is %s, should be 2.0" % sqlite.apilevel)
 
+    def test_deprecated_version(self):
+        msg = "deprecated and will be removed in Python 3.14"
+        for attr in "version", "version_info":
+            with self.subTest(attr=attr):
+                with self.assertWarnsRegex(DeprecationWarning, msg) as cm:
+                    getattr(sqlite, attr)
+                self.assertEqual(cm.filename,  __file__)
+                with self.assertWarnsRegex(DeprecationWarning, msg) as cm:
+                    getattr(sqlite.dbapi2, attr)
+                self.assertEqual(cm.filename,  __file__)
+
     def test_thread_safety(self):
         self.assertIn(sqlite.threadsafety, {0, 1, 3},
                       "threadsafety is %d, should be 0, 1 or 3" %
index 6b5ab49e3bf0e718987bc604feabea8ad8680d19..c3a4f9b9dededdb86c9f5de6eff6caaab0b16a19 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1456,6 +1456,7 @@ Edward K. Ream
 Chris Rebert
 Marc Recht
 John Redford
+Kalyan Reddy
 Terry J. Reedy
 Gareth Rees
 John Reese
diff --git a/Misc/NEWS.d/next/Library/2022-06-03-22-13-28.gh-issue-93370.tjfu9L.rst b/Misc/NEWS.d/next/Library/2022-06-03-22-13-28.gh-issue-93370.tjfu9L.rst
new file mode 100644 (file)
index 0000000..bd53150
--- /dev/null
@@ -0,0 +1 @@
+Deprecate :data:`sqlite3.version` and :data:`sqlite3.version_info`.
index 9b0e921511c56a688b30bd70f8f26c2a2ab84cb6..995d0946d9414ccdcf1da19a270f02ddf06ce503 100644 (file)
@@ -707,7 +707,7 @@ module_exec(PyObject *module)
         goto error;
     }
 
-    if (PyModule_AddStringConstant(module, "version", PYSQLITE_VERSION) < 0) {
+    if (PyModule_AddStringConstant(module, "_deprecated_version", PYSQLITE_VERSION) < 0) {
         goto error;
     }