Skip to content

Commit c88d33f

Browse files
committed
Deprecate VERSION attribute in xml.etree.ElementTree
1 parent c10ec48 commit c88d33f

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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.
4+
* The ``__version__`` and ``VERSION`` attributes have been deprecated in these
5+
standard library modules and will be removed in Python 3.20.
66
Use :py:data:`sys.version_info` instead.
77

88
- :mod:`argparse`
@@ -23,6 +23,7 @@ Pending removal in Python 3.20
2323
- :mod:`tabnanny`
2424
- :mod:`tkinter.font`
2525
- :mod:`tkinter.ttk`
26+
- :mod:`xml.etree.ElementTree`
2627
- :mod:`wsgiref.simple_server`
2728
- :mod:`zlib`
2829

Doc/whatsnew/3.15.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,8 +1018,8 @@ New deprecations
10181018

10191019
* ``__version__``
10201020

1021-
* The ``__version__`` attribute has been deprecated in these standard library
1022-
modules and will be removed in Python 3.20.
1021+
* The ``__version__`` and ``VERSION`` attributes have been deprecated in these
1022+
standard library modules and will be removed in Python 3.20.
10231023
Use :py:data:`sys.version_info` instead.
10241024

10251025
- :mod:`argparse`
@@ -1040,6 +1040,7 @@ New deprecations
10401040
- :mod:`tabnanny`
10411041
- :mod:`tkinter.font`
10421042
- :mod:`tkinter.ttk`
1043+
- :mod:`xml.etree.ElementTree`
10431044
- :mod:`wsgiref.simple_server`
10441045
- :mod:`zlib`
10451046

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}")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Deprecate ``VERSION`` from :mod:`xml.etree.ElementTree`. Patch by Hugo van
2+
Kemenade.

0 commit comments

Comments
 (0)