[Python-checkins] bpo-30485: Re-allow empty strings in ElementPath namespace mappings since they might actually be harmless and unused (and thus went undetected previously). (#12830)

Stefan Behnel webhook-mailer at python.org
Sun Apr 14 15:12:39 EDT 2019


https://github.com/python/cpython/commit/3c5a858ec6a4e5851903762770fe526a46d3c351
commit: 3c5a858ec6a4e5851903762770fe526a46d3c351
branch: master
author: Stefan Behnel <stefan_ml at behnel.de>
committer: GitHub <noreply at github.com>
date: 2019-04-14T21:12:34+02:00
summary:

bpo-30485: Re-allow empty strings in ElementPath namespace mappings since they might actually be harmless and unused (and thus went undetected previously). (#12830)

files:
M Lib/test/test_xml_etree.py
M Lib/xml/etree/ElementPath.py

diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 2f7a3b60b22d..f5b118b079ee 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -2466,9 +2466,6 @@ def test_findall_different_nsmaps(self):
         nsmap = {'xx': 'X', None: 'Y'}
         self.assertEqual(len(root.findall(".//xx:b", namespaces=nsmap)), 2)
         self.assertEqual(len(root.findall(".//b", namespaces=nsmap)), 1)
-        nsmap = {'xx': 'X', '': 'Y'}
-        with self.assertRaisesRegex(ValueError, 'namespace prefix'):
-            root.findall(".//xx:b", namespaces=nsmap)
 
     def test_bad_find(self):
         e = ET.XML(SAMPLE_XML)
diff --git a/Lib/xml/etree/ElementPath.py b/Lib/xml/etree/ElementPath.py
index 0e3854f9db22..4d231a7df656 100644
--- a/Lib/xml/etree/ElementPath.py
+++ b/Lib/xml/etree/ElementPath.py
@@ -275,8 +275,6 @@ def iterfind(elem, path, namespaces=None):
 
     cache_key = (path,)
     if namespaces:
-        if '' in namespaces:
-            raise ValueError("empty namespace prefix must be passed as None, not the empty string")
         if None in namespaces:
             cache_key += (namespaces[None],) + tuple(sorted(
                 item for item in namespaces.items() if item[0] is not None))



More information about the Python-checkins mailing list