]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-76007: Deprecate `VERSION` in `xml.etree.ElementTree` & `version` in `xml.sax...
authorHugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Thu, 18 Dec 2025 14:22:23 +0000 (16:22 +0200)
committerGitHub <noreply@github.com>
Thu, 18 Dec 2025 14:22:23 +0000 (14:22 +0000)
Doc/deprecations/pending-removal-in-3.20.rst
Doc/whatsnew/3.15.rst
Lib/test/test_sax.py
Lib/test/test_xml_etree.py
Lib/xml/etree/ElementTree.py
Lib/xml/sax/expatreader.py
Lib/xml/sax/handler.py
Misc/NEWS.d/next/Library/2025-12-16-14-21-20.gh-issue-76007.O4AmYl.rst [new file with mode: 0644]

index 185f20fbc6d125af5e613dd8df6ee90ff4a88020..4e4b2e1d5f8fff1f1ba00154fae793648531e38f 100644 (file)
@@ -1,9 +1,9 @@
 Pending removal in Python 3.20
 ------------------------------
 
-* The ``__version__`` attribute has been deprecated in these standard library
-  modules and will be removed in Python 3.20.
-  Use :py:data:`sys.version_info` instead.
+* The ``__version__``, ``version`` and ``VERSION`` attributes have been
+  deprecated in these standard library modules and will be removed in
+  Python 3.20. Use :py:data:`sys.version_info` instead.
 
   - :mod:`argparse`
   - :mod:`csv`
@@ -24,6 +24,9 @@ Pending removal in Python 3.20
   - :mod:`tkinter.font`
   - :mod:`tkinter.ttk`
   - :mod:`wsgiref.simple_server`
+  - :mod:`xml.etree.ElementTree`
+  - :mod:`!xml.sax.expatreader`
+  - :mod:`xml.sax.handler`
   - :mod:`zlib`
 
   (Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.)
index 7e032fe5df2fdfe574e7e866de996b987b403539..753b1990eb3308ae6ed064ffc9e4aa4ebb63976a 100644 (file)
@@ -1104,9 +1104,9 @@ New deprecations
 
 * ``__version__``
 
-  * The ``__version__`` attribute has been deprecated in these standard library
-    modules and will be removed in Python 3.20.
-    Use :py:data:`sys.version_info` instead.
+  * The ``__version__``, ``version`` and ``VERSION`` attributes have been
+    deprecated in these standard library modules and will be removed in
+    Python 3.20. Use :py:data:`sys.version_info` instead.
 
     - :mod:`argparse`
     - :mod:`csv`
@@ -1127,6 +1127,9 @@ New deprecations
     - :mod:`tkinter.font`
     - :mod:`tkinter.ttk`
     - :mod:`wsgiref.simple_server`
+    - :mod:`xml.etree.ElementTree`
+    - :mod:`!xml.sax.expatreader`
+    - :mod:`xml.sax.handler`
     - :mod:`zlib`
 
     (Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.)
index 5c10bcedc69bc614d3e7bafa39971e345b0732f3..29babd7bf6996ade144d30d4e52a72c10f2b876b 100644 (file)
@@ -1573,5 +1573,17 @@ class TestModuleAll(unittest.TestCase):
         check__all__(self, sax, extra=extra)
 
 
+class TestModule(unittest.TestCase):
+    def test_deprecated__version__and__date__(self):
+        for module in (sax.expatreader, sax.handler):
+            with self.subTest(module=module):
+                with self.assertWarnsRegex(
+                    DeprecationWarning,
+                    "'version' is deprecated and slated for removal in Python 3.20",
+                ) as cm:
+                    getattr(module, "version")
+                self.assertEqual(cm.filename, __file__)
+
+
 if __name__ == "__main__":
     unittest.main()
index 87811199706a1f675a85d38cb6997947cca883de..0178ed02b35be1075f62d9c960dee9342b901a45 100644 (file)
@@ -4705,6 +4705,19 @@ class C14NTest(unittest.TestCase):
 
 # --------------------------------------------------------------------
 
+
+class TestModule(unittest.TestCase):
+    def test_deprecated_version(self):
+        with self.assertWarnsRegex(
+            DeprecationWarning,
+            "'VERSION' is deprecated and slated for removal in Python 3.20",
+        ) as cm:
+                getattr(ET, "VERSION")
+        self.assertEqual(cm.filename, __file__)
+
+
+# --------------------------------------------------------------------
+
 def setUpModule(module=None):
     # When invoked without a module, runs the Python ET tests by loading pyET.
     # Otherwise, uses the given module as the ET.
index d8c0b1b621684bf3bc1dcef81c5a78d835586993..92f902b9a8b875457678e56ea188ec5a2aeb8aeb 100644 (file)
@@ -83,15 +83,12 @@ __all__ = [
     "SubElement",
     "tostring", "tostringlist",
     "TreeBuilder",
-    "VERSION",
     "XML", "XMLID",
     "XMLParser", "XMLPullParser",
     "register_namespace",
     "canonicalize", "C14NWriterTarget",
     ]
 
-VERSION = "1.3.0"
-
 import sys
 import re
 import warnings
@@ -2104,3 +2101,14 @@ except ImportError:
     pass
 else:
     _set_factories(Comment, ProcessingInstruction)
+
+
+# --------------------------------------------------------------------
+
+def __getattr__(name):
+    if name == "VERSION":
+        from warnings import _deprecated
+
+        _deprecated("VERSION", remove=(3, 20))
+        return "1.3.0"  # Do not change
+    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
index ba3c1e98517429bf8463fd36d10e31440ea6c178..37b1add28484877633591da6a7f2d18a9d62d4b2 100644 (file)
@@ -3,8 +3,6 @@ SAX driver for the pyexpat C module.  This driver works with
 pyexpat.__version__ == '2.22'.
 """
 
-version = "0.20"
-
 from xml.sax._exceptions import *
 from xml.sax.handler import feature_validation, feature_namespaces
 from xml.sax.handler import feature_namespace_prefixes
@@ -446,6 +444,16 @@ def create_parser(*args, **kwargs):
 
 # ---
 
+def __getattr__(name):
+    if name == "version":
+        from warnings import _deprecated
+
+        _deprecated("version", remove=(3, 20))
+        return "0.20"  # Do not change
+    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
+
+# ---
+
 if __name__ == "__main__":
     import xml.sax.saxutils
     p = create_parser()
index 3183c3fe96d74fb35cc6b185cdbce3dc7dc911b4..9c2e3af838a40f9e3b4fa0a7744d789552de56ba 100644 (file)
@@ -9,8 +9,6 @@ of the interfaces.
 $Id$
 """
 
-version = '2.0beta'
-
 #============================================================================
 #
 # HANDLER INTERFACES
@@ -385,3 +383,12 @@ class LexicalHandler:
 
     def endCDATA(self):
         """Reports the end of a CDATA marked section."""
+
+
+def __getattr__(name):
+    if name == "version":
+        from warnings import _deprecated
+
+        _deprecated("version", remove=(3, 20))
+        return "2.0beta"  # Do not change
+    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
diff --git a/Misc/NEWS.d/next/Library/2025-12-16-14-21-20.gh-issue-76007.O4AmYl.rst b/Misc/NEWS.d/next/Library/2025-12-16-14-21-20.gh-issue-76007.O4AmYl.rst
new file mode 100644 (file)
index 0000000..cfda732
--- /dev/null
@@ -0,0 +1,3 @@
+Deprecate ``VERSION`` from :mod:`xml.etree.ElementTree` and ``version`` from
+:mod:`!xml.sax.expatreader` and :mod:`xml.sax.handler`. Patch by Hugo van
+Kemenade.