Skip to content

Commit ffc58a9

Browse files
rawwarAlexWaygoodAA-Turnererlend-aasland
authored
gh-93370: Deprecate sqlite3.version and sqlite3.version_info (#93482)
Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent f8eae6f commit ffc58a9

File tree

7 files changed

+50
-2
lines changed

7 files changed

+50
-2
lines changed

Doc/library/sqlite3.rst

+10
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,22 @@ Module functions and constants
142142
The version number of this module, as a string. This is not the version of
143143
the SQLite library.
144144

145+
.. deprecated-removed:: 3.12 3.14
146+
This constant used to reflect the version number of the ``pysqlite``
147+
package, a third-party library which used to upstream changes to
148+
``sqlite3``. Today, it carries no meaning or practical value.
149+
145150

146151
.. data:: version_info
147152

148153
The version number of this module, as a tuple of integers. This is not the
149154
version of the SQLite library.
150155

156+
.. deprecated-removed:: 3.12 3.14
157+
This constant used to reflect the version number of the ``pysqlite``
158+
package, a third-party library which used to upstream changes to
159+
``sqlite3``. Today, it carries no meaning or practical value.
160+
151161

152162
.. data:: sqlite_version
153163

Lib/sqlite3/__init__.py

+13
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,16 @@
5555
"""
5656

5757
from sqlite3.dbapi2 import *
58+
from sqlite3.dbapi2 import (_deprecated_names,
59+
_deprecated_version_info,
60+
_deprecated_version)
61+
62+
63+
def __getattr__(name):
64+
if name in _deprecated_names:
65+
from warnings import warn
66+
67+
warn(f"{name} is deprecated and will be removed in Python 3.14",
68+
DeprecationWarning, stacklevel=2)
69+
return globals()[f"_deprecated_{name}"]
70+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Lib/sqlite3/dbapi2.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import collections.abc
2626

2727
from _sqlite3 import *
28+
from _sqlite3 import _deprecated_version
29+
30+
_deprecated_names = frozenset({"version", "version_info"})
2831

2932
paramstyle = "qmark"
3033

@@ -45,7 +48,7 @@ def TimeFromTicks(ticks):
4548
def TimestampFromTicks(ticks):
4649
return Timestamp(*time.localtime(ticks)[:6])
4750

48-
version_info = tuple([int(x) for x in version.split(".")])
51+
_deprecated_version_info = tuple(map(int, _deprecated_version.split(".")))
4952
sqlite_version_info = tuple([int(x) for x in sqlite_version.split(".")])
5053

5154
Binary = memoryview
@@ -85,3 +88,12 @@ def convert_timestamp(val):
8588
# Clean up namespace
8689

8790
del(register_adapters_and_converters)
91+
92+
def __getattr__(name):
93+
if name in _deprecated_names:
94+
from warnings import warn
95+
96+
warn(f"{name} is deprecated and will be removed in Python 3.14",
97+
DeprecationWarning, stacklevel=2)
98+
return globals()[f"_deprecated_{name}"]
99+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Lib/test/test_sqlite3/test_dbapi.py

+11
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ def test_api_level(self):
5757
self.assertEqual(sqlite.apilevel, "2.0",
5858
"apilevel is %s, should be 2.0" % sqlite.apilevel)
5959

60+
def test_deprecated_version(self):
61+
msg = "deprecated and will be removed in Python 3.14"
62+
for attr in "version", "version_info":
63+
with self.subTest(attr=attr):
64+
with self.assertWarnsRegex(DeprecationWarning, msg) as cm:
65+
getattr(sqlite, attr)
66+
self.assertEqual(cm.filename, __file__)
67+
with self.assertWarnsRegex(DeprecationWarning, msg) as cm:
68+
getattr(sqlite.dbapi2, attr)
69+
self.assertEqual(cm.filename, __file__)
70+
6071
def test_thread_safety(self):
6172
self.assertIn(sqlite.threadsafety, {0, 1, 3},
6273
"threadsafety is %d, should be 0, 1 or 3" %

Misc/ACKS

+1
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,7 @@ Edward K. Ream
14561456
Chris Rebert
14571457
Marc Recht
14581458
John Redford
1459+
Kalyan Reddy
14591460
Terry J. Reedy
14601461
Gareth Rees
14611462
John Reese
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate :data:`sqlite3.version` and :data:`sqlite3.version_info`.

Modules/_sqlite/module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ module_exec(PyObject *module)
707707
goto error;
708708
}
709709

710-
if (PyModule_AddStringConstant(module, "version", PYSQLITE_VERSION) < 0) {
710+
if (PyModule_AddStringConstant(module, "_deprecated_version", PYSQLITE_VERSION) < 0) {
711711
goto error;
712712
}
713713

0 commit comments

Comments
 (0)