Skip to content

Commit

Permalink
gh-93370: Deprecate sqlite3.version and sqlite3.version_info (#93482)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Waygood <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
Co-authored-by: Erlend E. Aasland <[email protected]>
  • Loading branch information
4 people authored Jun 7, 2022
1 parent f8eae6f commit ffc58a9
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Doc/library/sqlite3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions Lib/sqlite3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,16 @@
"""

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}")
14 changes: 13 additions & 1 deletion Lib/sqlite3/dbapi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import collections.abc

from _sqlite3 import *
from _sqlite3 import _deprecated_version

_deprecated_names = frozenset({"version", "version_info"})

paramstyle = "qmark"

Expand All @@ -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
Expand Down Expand Up @@ -85,3 +88,12 @@ def convert_timestamp(val):
# 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}")
11 changes: 11 additions & 0 deletions Lib/test/test_sqlite3/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def test_api_level(self):
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" %
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,7 @@ Edward K. Ream
Chris Rebert
Marc Recht
John Redford
Kalyan Reddy
Terry J. Reedy
Gareth Rees
John Reese
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate :data:`sqlite3.version` and :data:`sqlite3.version_info`.
2 changes: 1 addition & 1 deletion Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit ffc58a9

Please sign in to comment.