Skip to content

Commit d2abd57

Browse files
authored
gh-76007: Deprecate VERSION in xml.etree.ElementTree & version in xml.sax.expatreader & xml.sax.handler (#142898)
1 parent 0f01530 commit d2abd57

File tree

8 files changed

+70
-13
lines changed

8 files changed

+70
-13
lines changed

Doc/deprecations/pending-removal-in-3.20.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Pending removal in Python 3.20
22
------------------------------
33

4-
* The ``__version__`` attribute has been deprecated in these standard library
5-
modules and will be removed in Python 3.20.
6-
Use :py:data:`sys.version_info` instead.
4+
* The ``__version__``, ``version`` and ``VERSION`` attributes have been
5+
deprecated in these standard library modules and will be removed in
6+
Python 3.20. Use :py:data:`sys.version_info` instead.
77

88
- :mod:`argparse`
99
- :mod:`csv`
@@ -24,6 +24,9 @@ Pending removal in Python 3.20
2424
- :mod:`tkinter.font`
2525
- :mod:`tkinter.ttk`
2626
- :mod:`wsgiref.simple_server`
27+
- :mod:`xml.etree.ElementTree`
28+
- :mod:`!xml.sax.expatreader`
29+
- :mod:`xml.sax.handler`
2730
- :mod:`zlib`
2831

2932
(Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.)

Doc/whatsnew/3.15.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,9 @@ New deprecations
11041104

11051105
* ``__version__``
11061106

1107-
* The ``__version__`` attribute has been deprecated in these standard library
1108-
modules and will be removed in Python 3.20.
1109-
Use :py:data:`sys.version_info` instead.
1107+
* The ``__version__``, ``version`` and ``VERSION`` attributes have been
1108+
deprecated in these standard library modules and will be removed in
1109+
Python 3.20. Use :py:data:`sys.version_info` instead.
11101110

11111111
- :mod:`argparse`
11121112
- :mod:`csv`
@@ -1127,6 +1127,9 @@ New deprecations
11271127
- :mod:`tkinter.font`
11281128
- :mod:`tkinter.ttk`
11291129
- :mod:`wsgiref.simple_server`
1130+
- :mod:`xml.etree.ElementTree`
1131+
- :mod:`!xml.sax.expatreader`
1132+
- :mod:`xml.sax.handler`
11301133
- :mod:`zlib`
11311134

11321135
(Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.)

Lib/test/test_sax.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,5 +1573,17 @@ def test_all(self):
15731573
check__all__(self, sax, extra=extra)
15741574

15751575

1576+
class TestModule(unittest.TestCase):
1577+
def test_deprecated__version__and__date__(self):
1578+
for module in (sax.expatreader, sax.handler):
1579+
with self.subTest(module=module):
1580+
with self.assertWarnsRegex(
1581+
DeprecationWarning,
1582+
"'version' is deprecated and slated for removal in Python 3.20",
1583+
) as cm:
1584+
getattr(module, "version")
1585+
self.assertEqual(cm.filename, __file__)
1586+
1587+
15761588
if __name__ == "__main__":
15771589
unittest.main()

Lib/test/test_xml_etree.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4705,6 +4705,19 @@ def get_option(config, option_name, default=None):
47054705

47064706
# --------------------------------------------------------------------
47074707

4708+
4709+
class TestModule(unittest.TestCase):
4710+
def test_deprecated_version(self):
4711+
with self.assertWarnsRegex(
4712+
DeprecationWarning,
4713+
"'VERSION' is deprecated and slated for removal in Python 3.20",
4714+
) as cm:
4715+
getattr(ET, "VERSION")
4716+
self.assertEqual(cm.filename, __file__)
4717+
4718+
4719+
# --------------------------------------------------------------------
4720+
47084721
def setUpModule(module=None):
47094722
# When invoked without a module, runs the Python ET tests by loading pyET.
47104723
# Otherwise, uses the given module as the ET.

Lib/xml/etree/ElementTree.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,12 @@
8383
"SubElement",
8484
"tostring", "tostringlist",
8585
"TreeBuilder",
86-
"VERSION",
8786
"XML", "XMLID",
8887
"XMLParser", "XMLPullParser",
8988
"register_namespace",
9089
"canonicalize", "C14NWriterTarget",
9190
]
9291

93-
VERSION = "1.3.0"
94-
9592
import sys
9693
import re
9794
import warnings
@@ -2104,3 +2101,14 @@ def _escape_attrib_c14n(text):
21042101
pass
21052102
else:
21062103
_set_factories(Comment, ProcessingInstruction)
2104+
2105+
2106+
# --------------------------------------------------------------------
2107+
2108+
def __getattr__(name):
2109+
if name == "VERSION":
2110+
from warnings import _deprecated
2111+
2112+
_deprecated("VERSION", remove=(3, 20))
2113+
return "1.3.0" # Do not change
2114+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Lib/xml/sax/expatreader.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
pyexpat.__version__ == '2.22'.
44
"""
55

6-
version = "0.20"
7-
86
from xml.sax._exceptions import *
97
from xml.sax.handler import feature_validation, feature_namespaces
108
from xml.sax.handler import feature_namespace_prefixes
@@ -446,6 +444,16 @@ def create_parser(*args, **kwargs):
446444

447445
# ---
448446

447+
def __getattr__(name):
448+
if name == "version":
449+
from warnings import _deprecated
450+
451+
_deprecated("version", remove=(3, 20))
452+
return "0.20" # Do not change
453+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
454+
455+
# ---
456+
449457
if __name__ == "__main__":
450458
import xml.sax.saxutils
451459
p = create_parser()

Lib/xml/sax/handler.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
$Id$
1010
"""
1111

12-
version = '2.0beta'
13-
1412
#============================================================================
1513
#
1614
# HANDLER INTERFACES
@@ -385,3 +383,12 @@ def startCDATA(self):
385383

386384
def endCDATA(self):
387385
"""Reports the end of a CDATA marked section."""
386+
387+
388+
def __getattr__(name):
389+
if name == "version":
390+
from warnings import _deprecated
391+
392+
_deprecated("version", remove=(3, 20))
393+
return "2.0beta" # Do not change
394+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Deprecate ``VERSION`` from :mod:`xml.etree.ElementTree` and ``version`` from
2+
:mod:`!xml.sax.expatreader` and :mod:`xml.sax.handler`. Patch by Hugo van
3+
Kemenade.

0 commit comments

Comments
 (0)