From c88d33f875c5553fffc68bf6363234949b0d261e Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Tue, 16 Dec 2025 18:48:01 +0200 Subject: [PATCH 1/7] Deprecate VERSION attribute in xml.etree.ElementTree --- Doc/deprecations/pending-removal-in-3.20.rst | 5 +++-- Doc/whatsnew/3.15.rst | 5 +++-- Lib/test/test_xml_etree.py | 13 +++++++++++++ Lib/xml/etree/ElementTree.py | 14 +++++++++++--- .../2025-12-16-14-21-20.gh-issue-76007.O4AmYl.rst | 2 ++ 5 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-12-16-14-21-20.gh-issue-76007.O4AmYl.rst diff --git a/Doc/deprecations/pending-removal-in-3.20.rst b/Doc/deprecations/pending-removal-in-3.20.rst index 185f20fbc6d125..8b5844bdf341aa 100644 --- a/Doc/deprecations/pending-removal-in-3.20.rst +++ b/Doc/deprecations/pending-removal-in-3.20.rst @@ -1,8 +1,8 @@ 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. +* The ``__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` @@ -23,6 +23,7 @@ Pending removal in Python 3.20 - :mod:`tabnanny` - :mod:`tkinter.font` - :mod:`tkinter.ttk` + - :mod:`xml.etree.ElementTree` - :mod:`wsgiref.simple_server` - :mod:`zlib` diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 24a51f87c0f410..4d42ec9015b3db 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1018,8 +1018,8 @@ New deprecations * ``__version__`` - * The ``__version__`` attribute has been deprecated in these standard library - modules and will be removed in Python 3.20. + * The ``__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` @@ -1040,6 +1040,7 @@ New deprecations - :mod:`tabnanny` - :mod:`tkinter.font` - :mod:`tkinter.ttk` + - :mod:`xml.etree.ElementTree` - :mod:`wsgiref.simple_server` - :mod:`zlib` diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 87811199706a1f..0178ed02b35be1 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -4705,6 +4705,19 @@ def get_option(config, option_name, default=None): # -------------------------------------------------------------------- + +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. diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index d8c0b1b621684b..92f902b9a8b875 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -83,15 +83,12 @@ "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 @@ def _escape_attrib_c14n(text): 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}") 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 index 00000000000000..17a2c78579ec90 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-12-16-14-21-20.gh-issue-76007.O4AmYl.rst @@ -0,0 +1,2 @@ +Deprecate ``VERSION`` from :mod:`xml.etree.ElementTree`. Patch by Hugo van +Kemenade. From 2bdf4b9006455b709d053c7c089197b9a414b262 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Wed, 17 Dec 2025 19:35:40 +0200 Subject: [PATCH 2/7] Deprecate version attribute in xml.sax.expatreader --- Doc/deprecations/pending-removal-in-3.20.rst | 7 ++++--- Doc/whatsnew/3.15.rst | 7 ++++--- Lib/test/test_sax.py | 10 ++++++++++ Lib/xml/sax/expatreader.py | 14 +++++++++++--- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Doc/deprecations/pending-removal-in-3.20.rst b/Doc/deprecations/pending-removal-in-3.20.rst index 8b5844bdf341aa..aecd2ed3711f18 100644 --- a/Doc/deprecations/pending-removal-in-3.20.rst +++ b/Doc/deprecations/pending-removal-in-3.20.rst @@ -1,9 +1,9 @@ Pending removal in Python 3.20 ------------------------------ -* The ``__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. +* 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,7 @@ Pending removal in Python 3.20 - :mod:`tkinter.font` - :mod:`tkinter.ttk` - :mod:`xml.etree.ElementTree` + - :mod:`xml.sax.expatreader` - :mod:`wsgiref.simple_server` - :mod:`zlib` diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 4d42ec9015b3db..823507d6c35e6a 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1018,9 +1018,9 @@ New deprecations * ``__version__`` - * The ``__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. + * 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` @@ -1041,6 +1041,7 @@ New deprecations - :mod:`tkinter.font` - :mod:`tkinter.ttk` - :mod:`xml.etree.ElementTree` + - :mod:`xml.sax.expatreader` - :mod:`wsgiref.simple_server` - :mod:`zlib` diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 5c10bcedc69bc6..6b7fcebc8ce5ff 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -1573,5 +1573,15 @@ def test_all(self): check__all__(self, sax, extra=extra) +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(sax.expatreader, "version") + self.assertEqual(cm.filename, __file__) + + if __name__ == "__main__": unittest.main() diff --git a/Lib/xml/sax/expatreader.py b/Lib/xml/sax/expatreader.py index ba3c1e98517429..3e7f23a84d8630 100644 --- a/Lib/xml/sax/expatreader.py +++ b/Lib/xml/sax/expatreader.py @@ -3,8 +3,6 @@ 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,9 +444,19 @@ 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() p.setContentHandler(xml.sax.saxutils.XMLGenerator()) p.setErrorHandler(xml.sax.ErrorHandler()) - p.parse("http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml") + p.parse("https://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml") From 8007859b2a417f4fa17d837fc93439eaf880d2e3 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Wed, 17 Dec 2025 19:47:19 +0200 Subject: [PATCH 3/7] Deprecate version attribute in xml.sax.handler --- Doc/deprecations/pending-removal-in-3.20.rst | 3 ++- Doc/whatsnew/3.15.rst | 3 ++- Lib/test/test_sax.py | 16 +++++++++------- Lib/xml/sax/handler.py | 11 +++++++++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Doc/deprecations/pending-removal-in-3.20.rst b/Doc/deprecations/pending-removal-in-3.20.rst index aecd2ed3711f18..65986f19058d57 100644 --- a/Doc/deprecations/pending-removal-in-3.20.rst +++ b/Doc/deprecations/pending-removal-in-3.20.rst @@ -23,9 +23,10 @@ Pending removal in Python 3.20 - :mod:`tabnanny` - :mod:`tkinter.font` - :mod:`tkinter.ttk` + - :mod:`wsgiref.simple_server` - :mod:`xml.etree.ElementTree` - :mod:`xml.sax.expatreader` - - :mod:`wsgiref.simple_server` + - :mod:`xml.sax.handler` - :mod:`zlib` (Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 823507d6c35e6a..5d47376760ae06 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1040,9 +1040,10 @@ New deprecations - :mod:`tabnanny` - :mod:`tkinter.font` - :mod:`tkinter.ttk` + - :mod:`wsgiref.simple_server` - :mod:`xml.etree.ElementTree` - :mod:`xml.sax.expatreader` - - :mod:`wsgiref.simple_server` + - :mod:`xml.sax.handler` - :mod:`zlib` (Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.) diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 6b7fcebc8ce5ff..29babd7bf6996a 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -1574,13 +1574,15 @@ def test_all(self): 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(sax.expatreader, "version") - self.assertEqual(cm.filename, __file__) + 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__": diff --git a/Lib/xml/sax/handler.py b/Lib/xml/sax/handler.py index 3183c3fe96d74f..9c2e3af838a40f 100644 --- a/Lib/xml/sax/handler.py +++ b/Lib/xml/sax/handler.py @@ -9,8 +9,6 @@ $Id$ """ -version = '2.0beta' - #============================================================================ # # HANDLER INTERFACES @@ -385,3 +383,12 @@ def startCDATA(self): 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}") From 020cc5c80e495fa87fcf103984b5960a48deaa6e Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Wed, 17 Dec 2025 19:56:53 +0200 Subject: [PATCH 4/7] Deprecate version attribute in xml.sax.expatreader and xml.sax.handler --- .../next/Library/2025-12-16-14-21-20.gh-issue-76007.O4AmYl.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 index 17a2c78579ec90..9a7d514a80bc38 100644 --- 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 @@ -1,2 +1,3 @@ -Deprecate ``VERSION`` from :mod:`xml.etree.ElementTree`. Patch by Hugo van +Deprecate ``VERSION`` from :mod:`xml.etree.ElementTree` and ``version`` from +:mod:`xml.sax.expatreader` and :mod:`xml.sax.handler`. Patch by Hugo van Kemenade. From cecae3971fa11a8e7f4f6d1cfeacf5a186e9c9a7 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Wed, 17 Dec 2025 20:07:17 +0200 Subject: [PATCH 5/7] Fix Sphinx warning --- Doc/deprecations/pending-removal-in-3.20.rst | 2 +- Doc/whatsnew/3.15.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/deprecations/pending-removal-in-3.20.rst b/Doc/deprecations/pending-removal-in-3.20.rst index 65986f19058d57..4e4b2e1d5f8fff 100644 --- a/Doc/deprecations/pending-removal-in-3.20.rst +++ b/Doc/deprecations/pending-removal-in-3.20.rst @@ -25,7 +25,7 @@ Pending removal in Python 3.20 - :mod:`tkinter.ttk` - :mod:`wsgiref.simple_server` - :mod:`xml.etree.ElementTree` - - :mod:`xml.sax.expatreader` + - :mod:`!xml.sax.expatreader` - :mod:`xml.sax.handler` - :mod:`zlib` diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 5d47376760ae06..219b72234f7e98 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1042,7 +1042,7 @@ New deprecations - :mod:`tkinter.ttk` - :mod:`wsgiref.simple_server` - :mod:`xml.etree.ElementTree` - - :mod:`xml.sax.expatreader` + - :mod:`!xml.sax.expatreader` - :mod:`xml.sax.handler` - :mod:`zlib` From 5f1f5a9e023888555333cb13a049a8d40b893aa2 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Wed, 17 Dec 2025 20:54:06 +0200 Subject: [PATCH 6/7] Fix Sphinx warning --- .../next/Library/2025-12-16-14-21-20.gh-issue-76007.O4AmYl.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 9a7d514a80bc38..cfda7327e8fee8 100644 --- 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 @@ -1,3 +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 +:mod:`!xml.sax.expatreader` and :mod:`xml.sax.handler`. Patch by Hugo van Kemenade. From b296d6b5c5e40c4ab4b95c9595314861aa852a14 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Thu, 18 Dec 2025 15:53:48 +0200 Subject: [PATCH 7/7] Revert https --- Lib/xml/sax/expatreader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/xml/sax/expatreader.py b/Lib/xml/sax/expatreader.py index 3e7f23a84d8630..37b1add2848487 100644 --- a/Lib/xml/sax/expatreader.py +++ b/Lib/xml/sax/expatreader.py @@ -459,4 +459,4 @@ def __getattr__(name): p = create_parser() p.setContentHandler(xml.sax.saxutils.XMLGenerator()) p.setErrorHandler(xml.sax.ErrorHandler()) - p.parse("https://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml") + p.parse("http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml")