[Python-checkins] gh-96175: add missing self._localName assignment in `xml.dom.minidom.Attr` (#96176)

JelleZijlstra webhook-mailer at python.org
Tue Aug 23 12:16:15 EDT 2022


https://github.com/python/cpython/commit/58f6953d6d3fe20d972bfa2f6e982206adcf1353
commit: 58f6953d6d3fe20d972bfa2f6e982206adcf1353
branch: main
author: Kevin Kirsche <Kev.Kirsche+GitHub at gmail.com>
committer: JelleZijlstra <jelle.zijlstra at gmail.com>
date: 2022-08-23T09:16:02-07:00
summary:

gh-96175: add missing self._localName assignment in `xml.dom.minidom.Attr` (#96176)

X-Ref: https://github.com/python/typeshed/pull/8590#discussion_r951473977

Co-authored-by: Jelle Zijlstra <jelle.zijlstra at gmail.com>

files:
A Misc/NEWS.d/next/Library/2022-08-22-13-54-20.gh-issue-96175.bH7zGU.rst
M Lib/test/test_minidom.py
M Lib/xml/dom/minidom.py

diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py
index 97620258d82f..ef38c362103f 100644
--- a/Lib/test/test_minidom.py
+++ b/Lib/test/test_minidom.py
@@ -9,7 +9,7 @@
 import pyexpat
 import xml.dom.minidom
 
-from xml.dom.minidom import parse, Node, Document, parseString
+from xml.dom.minidom import parse, Attr, Node, Document, parseString
 from xml.dom.minidom import getDOMImplementation
 from xml.parsers.expat import ExpatError
 
@@ -77,6 +77,20 @@ def testParseFromTextFile(self):
             dom.unlink()
             self.confirm(isinstance(dom, Document))
 
+    def testAttrModeSetsParamsAsAttrs(self):
+        attr = Attr("qName", "namespaceURI", "localName", "prefix")
+        self.assertEqual(attr.name, "qName")
+        self.assertEqual(attr.namespaceURI, "namespaceURI")
+        self.assertEqual(attr.prefix, "prefix")
+        self.assertEqual(attr.localName, "localName")
+
+    def testAttrModeSetsNonOptionalAttrs(self):
+        attr = Attr("qName", "namespaceURI", None, "prefix")
+        self.assertEqual(attr.name, "qName")
+        self.assertEqual(attr.namespaceURI, "namespaceURI")
+        self.assertEqual(attr.prefix, "prefix")
+        self.assertEqual(attr.localName, attr.name)
+
     def testGetElementsByTagName(self):
         dom = parse(tstfile)
         self.confirm(dom.getElementsByTagName("LI") == \
diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py
index d09ef5e7d037..ef8a159833bb 100644
--- a/Lib/xml/dom/minidom.py
+++ b/Lib/xml/dom/minidom.py
@@ -358,6 +358,8 @@ def __init__(self, qName, namespaceURI=EMPTY_NAMESPACE, localName=None,
         self._name = qName
         self.namespaceURI = namespaceURI
         self._prefix = prefix
+        if localName is not None:
+            self._localName = localName
         self.childNodes = NodeList()
 
         # Add the single child node that represents the value of the attr
diff --git a/Misc/NEWS.d/next/Library/2022-08-22-13-54-20.gh-issue-96175.bH7zGU.rst b/Misc/NEWS.d/next/Library/2022-08-22-13-54-20.gh-issue-96175.bH7zGU.rst
new file mode 100644
index 000000000000..c34eff22b3d4
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-08-22-13-54-20.gh-issue-96175.bH7zGU.rst
@@ -0,0 +1 @@
+Fix unused ``localName`` parameter in the ``Attr`` class in :mod:`xml.dom.minidom`.



More information about the Python-checkins mailing list