From 243a74ca93754841458a7e6fb68e4c774a983a1d Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Mon, 20 Oct 2025 17:11:37 +0545 Subject: [PATCH 01/19] gh-140123: Make ElementTree.find use registered global namespaces ElementTree.find, findall, findtext, and iterfind now use the global _namespace_map as fallback when no namespaces argument is provided. Fixes inconsistencies between ElementTree and ElementPath when using ET.register_namespace. --- Lib/test/test_xml_etree.py | 30 +++++++++++++++++++++++++++++- Lib/xml/etree/ElementTree.py | 9 +++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index f65baa0cfae2ad..50f2765fe584b1 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -21,6 +21,7 @@ import unittest.mock as mock import warnings import weakref +import xml.etree.ElementTree as ET from contextlib import nullcontext from functools import partial @@ -32,7 +33,6 @@ from test.support.import_helper import import_fresh_module from test.support.os_helper import TESTFN - # pyET is the pure-Python implementation. # # ET is pyET in test_xml_etree and is the C accelerated version in @@ -4668,6 +4668,34 @@ def cleanup(): old_factories = ET._set_factories(ET.Comment, ET.PI) unittest.addModuleCleanup(ET._set_factories, *old_factories) +class TestElementTreeGlobalNamespace(unittest.TestCase): + def test_find_uses_registered_namespace(self): + xml_data = """ + + Apple + + """ + ET.register_namespace("h", "http://www.w3.org/TR/html4/") + tree = ET.ElementTree(ET.fromstring(xml_data)) + + # should work without passing namespaces explicitly + elem = tree.find(".//h:title") + self.assertIsNotNone(elem) + self.assertEqual(elem.tag, "{http://www.w3.org/TR/html4/}title") + + def test_findall_and_findtext_with_global_ns(self): + xml_data = """ + Apple + Banana + """ + ET.register_namespace("h", "http://www.w3.org/TR/html4/") + root = ET.fromstring(xml_data) + + items = root.findall(".//h:item") + self.assertEqual(len(items), 2) + + first_text = root.findtext(".//h:item") + self.assertEqual(first_text, "Apple") if __name__ == '__main__': unittest.main() diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index dafe5b1b8a0c3f..70029f8fe26479 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -102,6 +102,7 @@ import weakref from . import ElementPath +import xml.etree.ElementTree as _ET class ParseError(SyntaxError): @@ -282,6 +283,8 @@ def find(self, path, namespaces=None): Return the first matching element, or None if no element was found. """ + if namespaces is None: + namespaces = {v: k for k, v in _ET._namespace_map.items() if v} return ElementPath.find(self, path, namespaces) def findtext(self, path, default=None, namespaces=None): @@ -296,6 +299,8 @@ def findtext(self, path, default=None, namespaces=None): content, the empty string is returned. """ + if namespaces is None: + namespaces = {v: k for k, v in _ET._namespace_map.items() if v} return ElementPath.findtext(self, path, default, namespaces) def findall(self, path, namespaces=None): @@ -307,6 +312,8 @@ def findall(self, path, namespaces=None): Returns list containing all matching elements in document order. """ + if namespaces is None: + namespaces = {v: k for k, v in _ET._namespace_map.items() if v} return ElementPath.findall(self, path, namespaces) def iterfind(self, path, namespaces=None): @@ -318,6 +325,8 @@ def iterfind(self, path, namespaces=None): Return an iterable yielding all matching elements in document order. """ + if namespaces is None: + namespaces = {v: k for k, v in _ET._namespace_map.items() if v} return ElementPath.iterfind(self, path, namespaces) def clear(self): From 0ddb4cb6c7e9832f886cf1571b3ce0cc535f08cb Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Mon, 20 Oct 2025 18:47:01 +0545 Subject: [PATCH 02/19] GH-140123: ElementTree.find uses registered namespaces when omitted --- .../Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst diff --git a/Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst b/Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst new file mode 100644 index 00000000000000..ef5ea2878d69e2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst @@ -0,0 +1,4 @@ +ElementTree.find(), ElementTree.findall(), ElementTree.findtext(), and +ElementTree.iterfind() now automatically use globally registered namespaces +(via xml.etree.ElementTree.register_namespace) when the *namespaces* +argument is omitted. From 95cddc95a83545e7718c12d6942d07996a131f2d Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Mon, 20 Oct 2025 20:48:51 +0545 Subject: [PATCH 03/19] xml.etree: Fix namespace prefix resolution in ElementPath xpath_tokenizer (GH-140123) The namespace prefix resolution in ElementPath.xpath_tokenizer now properly uses globally registered namespaces after trying local namespaces first. This ensures consistent namespace handling across both Python and C implementations. --- Lib/xml/etree/ElementPath.py | 13 +++++++++---- .../Library/2023-10-20-14-30-00.gh-issue-140123.rst | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst diff --git a/Lib/xml/etree/ElementPath.py b/Lib/xml/etree/ElementPath.py index dc6bd28c03137d..18bee5b60bf129 100644 --- a/Lib/xml/etree/ElementPath.py +++ b/Lib/xml/etree/ElementPath.py @@ -18,6 +18,8 @@ # # fredrik@pythonware.com # http://www.pythonware.com + +from . import ElementTree # # -------------------------------------------------------------------- # The ElementTree toolkit is @@ -79,11 +81,14 @@ def xpath_tokenizer(pattern, namespaces=None): if tag and tag[0] != "{": if ":" in tag: prefix, uri = tag.split(":", 1) - try: - if not namespaces: - raise KeyError + if namespaces and prefix in namespaces: + # Use the passed-in namespace map first yield ttype, "{%s}%s" % (namespaces[prefix], uri) - except KeyError: + elif prefix in ElementTree._namespace_map: + # Then check the global registry + yield ttype, "{%s}%s" % (ElementTree._namespace_map[prefix], uri) + else: + # No namespace found, raise error raise SyntaxError("prefix %r not found in prefix map" % prefix) from None elif default_namespace and not parsing_attribute: yield ttype, "{%s}%s" % (default_namespace, tag) diff --git a/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst b/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst new file mode 100644 index 00000000000000..89765ca4c2476c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst @@ -0,0 +1 @@ +ElementTree.find() and similar methods now properly use globally registered namespaces when resolving namespace prefixes in XPath expressions. \ No newline at end of file From e3997b08a292b4bba5be79a9e1331a13f879a170 Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Mon, 20 Oct 2025 21:20:24 +0545 Subject: [PATCH 04/19] Fix linter issues: Remove duplicate ET import and add missing newline - Remove duplicate import of xml.etree.ElementTree as ET - Add missing newline at end of NEWS entry file --- Lib/test/test_xml_etree.py | 1 - .../NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 50f2765fe584b1..42da5f9b3b0eee 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -21,7 +21,6 @@ import unittest.mock as mock import warnings import weakref -import xml.etree.ElementTree as ET from contextlib import nullcontext from functools import partial diff --git a/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst b/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst index 89765ca4c2476c..fc47317290fbfb 100644 --- a/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst +++ b/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst @@ -1 +1 @@ -ElementTree.find() and similar methods now properly use globally registered namespaces when resolving namespace prefixes in XPath expressions. \ No newline at end of file +ElementTree.find() and similar methods now properly use globally registered namespaces when resolving namespace prefixes in XPath expressions. From c5d15125147cf7a354df88f807a528a568e0ca21 Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Mon, 20 Oct 2025 21:48:29 +0545 Subject: [PATCH 05/19] Keep full NEWS entry for #140123, remove duplicate draft --- Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst diff --git a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst new file mode 100644 index 00000000000000..39e92736dab0b0 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst @@ -0,0 +1,5 @@ +ElementTree.find(), ElementTree.findall(), ElementTree.findtext(), and +ElementTree.iterfind() now automatically use globally registered namespaces +(via xml.etree.ElementTree.register_namespace) when the *namespaces* +argument is omitted. + From b2f57577a5fa590dfeb3628304178786379e48b5 Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Mon, 20 Oct 2025 22:02:55 +0545 Subject: [PATCH 06/19] Rename NEWS entry to include section for blurb: #140123 --- .../next/Library/2025-10-20.gh-issue-140123.bugfix.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst diff --git a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst new file mode 100644 index 00000000000000..39e92736dab0b0 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst @@ -0,0 +1,5 @@ +ElementTree.find(), ElementTree.findall(), ElementTree.findtext(), and +ElementTree.iterfind() now automatically use globally registered namespaces +(via xml.etree.ElementTree.register_namespace) when the *namespaces* +argument is omitted. + From 9eda02e1836a0edb5179ec02deeda6d5763e71da Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Mon, 20 Oct 2025 23:05:19 +0545 Subject: [PATCH 07/19] fix blurb format error --- Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst index 39e92736dab0b0..ef5ea2878d69e2 100644 --- a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst +++ b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst @@ -2,4 +2,3 @@ ElementTree.find(), ElementTree.findall(), ElementTree.findtext(), and ElementTree.iterfind() now automatically use globally registered namespaces (via xml.etree.ElementTree.register_namespace) when the *namespaces* argument is omitted. - From af2dfbff4c88ab6f8e185d786e064a5377f21fed Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Tue, 21 Oct 2025 09:36:24 +0545 Subject: [PATCH 08/19] Deleted News file causing failing tests --- .../next/Library/2023-10-20-14-30-00.gh-issue-140123.rst | 1 - .../Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst | 4 ---- .../next/Library/2025-10-20.gh-issue-140123.bugfix.rst | 4 ---- Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst | 5 ----- 4 files changed, 14 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst delete mode 100644 Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst delete mode 100644 Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst delete mode 100644 Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst diff --git a/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst b/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst deleted file mode 100644 index fc47317290fbfb..00000000000000 --- a/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst +++ /dev/null @@ -1 +0,0 @@ -ElementTree.find() and similar methods now properly use globally registered namespaces when resolving namespace prefixes in XPath expressions. diff --git a/Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst b/Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst deleted file mode 100644 index ef5ea2878d69e2..00000000000000 --- a/Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst +++ /dev/null @@ -1,4 +0,0 @@ -ElementTree.find(), ElementTree.findall(), ElementTree.findtext(), and -ElementTree.iterfind() now automatically use globally registered namespaces -(via xml.etree.ElementTree.register_namespace) when the *namespaces* -argument is omitted. diff --git a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst deleted file mode 100644 index ef5ea2878d69e2..00000000000000 --- a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst +++ /dev/null @@ -1,4 +0,0 @@ -ElementTree.find(), ElementTree.findall(), ElementTree.findtext(), and -ElementTree.iterfind() now automatically use globally registered namespaces -(via xml.etree.ElementTree.register_namespace) when the *namespaces* -argument is omitted. diff --git a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst deleted file mode 100644 index 39e92736dab0b0..00000000000000 --- a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst +++ /dev/null @@ -1,5 +0,0 @@ -ElementTree.find(), ElementTree.findall(), ElementTree.findtext(), and -ElementTree.iterfind() now automatically use globally registered namespaces -(via xml.etree.ElementTree.register_namespace) when the *namespaces* -argument is omitted. - From 8ae041ca889ccf7a7c888e8c0906e859f894f202 Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Tue, 21 Oct 2025 10:30:29 +0545 Subject: [PATCH 09/19] Fix: avoid mutable default arguments in ElementTree --- Lib/xml/etree/ElementTree.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index 70029f8fe26479..043118fb661889 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -168,7 +168,9 @@ class Element: """ - def __init__(self, tag, attrib={}, **extra): + def __init__(self, tag, attrib=None, **extra): + if attrib is None: + attrib = {} if not isinstance(attrib, dict): raise TypeError("attrib must be dict, not %s" % ( attrib.__class__.__name__,)) From 8d4995868d1468d98e0e43f1c998ba7394e5db0f Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Mon, 20 Oct 2025 17:11:37 +0545 Subject: [PATCH 10/19] gh-140123: Make ElementTree.find use registered global namespaces ElementTree.find, findall, findtext, and iterfind now use the global _namespace_map as fallback when no namespaces argument is provided. Fixes inconsistencies between ElementTree and ElementPath when using ET.register_namespace. --- Lib/test/test_xml_etree.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 42da5f9b3b0eee..50f2765fe584b1 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -21,6 +21,7 @@ import unittest.mock as mock import warnings import weakref +import xml.etree.ElementTree as ET from contextlib import nullcontext from functools import partial From 49d517dffecd682a835a60784fc6f4f7358b1b7a Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Mon, 20 Oct 2025 18:47:01 +0545 Subject: [PATCH 11/19] GH-140123: ElementTree.find uses registered namespaces when omitted --- .../Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst diff --git a/Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst b/Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst new file mode 100644 index 00000000000000..ef5ea2878d69e2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst @@ -0,0 +1,4 @@ +ElementTree.find(), ElementTree.findall(), ElementTree.findtext(), and +ElementTree.iterfind() now automatically use globally registered namespaces +(via xml.etree.ElementTree.register_namespace) when the *namespaces* +argument is omitted. From 145d47f782fe52664d3e7a0d25db28cf29a4e360 Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Mon, 20 Oct 2025 20:48:51 +0545 Subject: [PATCH 12/19] xml.etree: Fix namespace prefix resolution in ElementPath xpath_tokenizer (GH-140123) The namespace prefix resolution in ElementPath.xpath_tokenizer now properly uses globally registered namespaces after trying local namespaces first. This ensures consistent namespace handling across both Python and C implementations. --- Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst diff --git a/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst b/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst new file mode 100644 index 00000000000000..89765ca4c2476c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst @@ -0,0 +1 @@ +ElementTree.find() and similar methods now properly use globally registered namespaces when resolving namespace prefixes in XPath expressions. \ No newline at end of file From 0a86da976ac3a106db45cc3a195b80ae710520eb Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Mon, 20 Oct 2025 21:20:24 +0545 Subject: [PATCH 13/19] Fix linter issues: Remove duplicate ET import and add missing newline - Remove duplicate import of xml.etree.ElementTree as ET - Add missing newline at end of NEWS entry file --- Lib/test/test_xml_etree.py | 1 - .../NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 50f2765fe584b1..42da5f9b3b0eee 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -21,7 +21,6 @@ import unittest.mock as mock import warnings import weakref -import xml.etree.ElementTree as ET from contextlib import nullcontext from functools import partial diff --git a/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst b/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst index 89765ca4c2476c..fc47317290fbfb 100644 --- a/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst +++ b/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst @@ -1 +1 @@ -ElementTree.find() and similar methods now properly use globally registered namespaces when resolving namespace prefixes in XPath expressions. \ No newline at end of file +ElementTree.find() and similar methods now properly use globally registered namespaces when resolving namespace prefixes in XPath expressions. From 28c55c8be7cdcf87cfd31e7f969fb61d12b3f2b5 Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Mon, 20 Oct 2025 21:48:29 +0545 Subject: [PATCH 14/19] Keep full NEWS entry for #140123, remove duplicate draft --- Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst diff --git a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst new file mode 100644 index 00000000000000..39e92736dab0b0 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst @@ -0,0 +1,5 @@ +ElementTree.find(), ElementTree.findall(), ElementTree.findtext(), and +ElementTree.iterfind() now automatically use globally registered namespaces +(via xml.etree.ElementTree.register_namespace) when the *namespaces* +argument is omitted. + From 1a9208ebd1d7e1ed4fe7a48c5924f99cb2edf771 Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Mon, 20 Oct 2025 22:02:55 +0545 Subject: [PATCH 15/19] Rename NEWS entry to include section for blurb: #140123 --- .../next/Library/2025-10-20.gh-issue-140123.bugfix.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst diff --git a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst new file mode 100644 index 00000000000000..39e92736dab0b0 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst @@ -0,0 +1,5 @@ +ElementTree.find(), ElementTree.findall(), ElementTree.findtext(), and +ElementTree.iterfind() now automatically use globally registered namespaces +(via xml.etree.ElementTree.register_namespace) when the *namespaces* +argument is omitted. + From ef4fd3fcb1e6608b250dd217d9c7d43638741b79 Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Mon, 20 Oct 2025 23:05:19 +0545 Subject: [PATCH 16/19] fix blurb format error --- Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst index 39e92736dab0b0..ef5ea2878d69e2 100644 --- a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst +++ b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst @@ -2,4 +2,3 @@ ElementTree.find(), ElementTree.findall(), ElementTree.findtext(), and ElementTree.iterfind() now automatically use globally registered namespaces (via xml.etree.ElementTree.register_namespace) when the *namespaces* argument is omitted. - From 33d8aac48bb3e88f36d56ae15273e89b1825d4d2 Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Tue, 21 Oct 2025 09:36:24 +0545 Subject: [PATCH 17/19] Deleted News file causing failing tests --- .../next/Library/2023-10-20-14-30-00.gh-issue-140123.rst | 1 - .../Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst | 4 ---- .../next/Library/2025-10-20.gh-issue-140123.bugfix.rst | 4 ---- Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst | 5 ----- 4 files changed, 14 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst delete mode 100644 Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst delete mode 100644 Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst delete mode 100644 Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst diff --git a/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst b/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst deleted file mode 100644 index fc47317290fbfb..00000000000000 --- a/Misc/NEWS.d/next/Library/2023-10-20-14-30-00.gh-issue-140123.rst +++ /dev/null @@ -1 +0,0 @@ -ElementTree.find() and similar methods now properly use globally registered namespaces when resolving namespace prefixes in XPath expressions. diff --git a/Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst b/Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst deleted file mode 100644 index ef5ea2878d69e2..00000000000000 --- a/Misc/NEWS.d/next/Library/2025-10-20-18-46-47.gh-issue-140123.FpBRZz.rst +++ /dev/null @@ -1,4 +0,0 @@ -ElementTree.find(), ElementTree.findall(), ElementTree.findtext(), and -ElementTree.iterfind() now automatically use globally registered namespaces -(via xml.etree.ElementTree.register_namespace) when the *namespaces* -argument is omitted. diff --git a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst deleted file mode 100644 index ef5ea2878d69e2..00000000000000 --- a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.bugfix.rst +++ /dev/null @@ -1,4 +0,0 @@ -ElementTree.find(), ElementTree.findall(), ElementTree.findtext(), and -ElementTree.iterfind() now automatically use globally registered namespaces -(via xml.etree.ElementTree.register_namespace) when the *namespaces* -argument is omitted. diff --git a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst b/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst deleted file mode 100644 index 39e92736dab0b0..00000000000000 --- a/Misc/NEWS.d/next/Library/2025-10-20.gh-issue-140123.rst +++ /dev/null @@ -1,5 +0,0 @@ -ElementTree.find(), ElementTree.findall(), ElementTree.findtext(), and -ElementTree.iterfind() now automatically use globally registered namespaces -(via xml.etree.ElementTree.register_namespace) when the *namespaces* -argument is omitted. - From 8c6a6e4735ced95ec10b5ccdcf80111e74d753af Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 21 Oct 2025 04:00:30 +0000 Subject: [PATCH 18/19] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2025-10-21-04-00-29.gh-issue-140123.Cc6xGI.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-10-21-04-00-29.gh-issue-140123.Cc6xGI.rst diff --git a/Misc/NEWS.d/next/Library/2025-10-21-04-00-29.gh-issue-140123.Cc6xGI.rst b/Misc/NEWS.d/next/Library/2025-10-21-04-00-29.gh-issue-140123.Cc6xGI.rst new file mode 100644 index 00000000000000..7a97878c011310 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-10-21-04-00-29.gh-issue-140123.Cc6xGI.rst @@ -0,0 +1,2 @@ +ElementTree.find(), ElementTree.findall(), and ElementTree.findtext() now +use registered namespaces consistently with ElementPath. From b76e83371a63814f7631d40f6583bcb52585a2f9 Mon Sep 17 00:00:00 2001 From: Sangam Paudel Date: Tue, 21 Oct 2025 11:07:58 +0545 Subject: [PATCH 19/19] xml.etree: Fix XMLParser parser attribute handling Fix issue where self.parser was incorrectly initialized in XMLParser.__init__. The parser was being created twice and the wrong instance was being assigned. Now both self.parser and self._parser point to the same parser instance, maintaining backward compatibility and fixing the AttributeError in tests. --- Lib/xml/etree/ElementTree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index 043118fb661889..44e9c0cfac8495 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -1551,7 +1551,7 @@ def __init__(self, *, target=None, encoding=None): parser = expat.ParserCreate(encoding, "}") if target is None: target = TreeBuilder() - # underscored names are provided for compatibility only + # both names are provided for compatibility self.parser = self._parser = parser self.target = self._target = target self._error = expat.error