Skip to content

Commit d7eea0f

Browse files
gh-96175: add missing self._localName assignment in xml.dom.minidom.Attr (GH-96176)
X-Ref: https://github.com/python/typeshed/pull/8590GH-discussion_r951473977 Co-authored-by: Jelle Zijlstra <[email protected]> (cherry picked from commit 58f6953) Co-authored-by: Kevin Kirsche <[email protected]>
1 parent 0aed1e7 commit d7eea0f

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Lib/test/test_minidom.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pyexpat
1010
import xml.dom.minidom
1111

12-
from xml.dom.minidom import parse, Node, Document, parseString
12+
from xml.dom.minidom import parse, Attr, Node, Document, parseString
1313
from xml.dom.minidom import getDOMImplementation
1414
from xml.parsers.expat import ExpatError
1515

@@ -77,6 +77,20 @@ def testParseFromTextFile(self):
7777
dom.unlink()
7878
self.confirm(isinstance(dom, Document))
7979

80+
def testAttrModeSetsParamsAsAttrs(self):
81+
attr = Attr("qName", "namespaceURI", "localName", "prefix")
82+
self.assertEqual(attr.name, "qName")
83+
self.assertEqual(attr.namespaceURI, "namespaceURI")
84+
self.assertEqual(attr.prefix, "prefix")
85+
self.assertEqual(attr.localName, "localName")
86+
87+
def testAttrModeSetsNonOptionalAttrs(self):
88+
attr = Attr("qName", "namespaceURI", None, "prefix")
89+
self.assertEqual(attr.name, "qName")
90+
self.assertEqual(attr.namespaceURI, "namespaceURI")
91+
self.assertEqual(attr.prefix, "prefix")
92+
self.assertEqual(attr.localName, attr.name)
93+
8094
def testGetElementsByTagName(self):
8195
dom = parse(tstfile)
8296
self.confirm(dom.getElementsByTagName("LI") == \

Lib/xml/dom/minidom.py

+2
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ def __init__(self, qName, namespaceURI=EMPTY_NAMESPACE, localName=None,
358358
self._name = qName
359359
self.namespaceURI = namespaceURI
360360
self._prefix = prefix
361+
if localName is not None:
362+
self._localName = localName
361363
self.childNodes = NodeList()
362364

363365
# Add the single child node that represents the value of the attr
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix unused ``localName`` parameter in the ``Attr`` class in :mod:`xml.dom.minidom`.

0 commit comments

Comments
 (0)