From 1d852009f062e5d87c23c373e0894566e08881af Mon Sep 17 00:00:00 2001 From: Som Date: Tue, 11 Aug 2026 18:09:14 +0000 Subject: [PATCH] gh-100710: Add nodeValue default to xml.dom.minidom.Node base class Node.nodeValue is documented per the DOM interface but was never declared on the base Node class in Lib/xml/dom/minidom.py, only on its concrete subclasses. At runtime this was harmless (every subclass already sets it), but static type checkers such as Pylance flag `.nodeValue` access on Node-typed references as an unknown member. Add nodeValue = None as a class-level default on Node, matching the existing pattern for namespaceURI/parentNode/etc. --- Lib/test/test_minidom.py | 9 +++++++++ Lib/xml/dom/minidom.py | 1 + .../2026-08-11-18-30-00.gh-issue-100710.6V5Prz.rst | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-08-11-18-30-00.gh-issue-100710.6V5Prz.rst diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index 46249e5138aed5..ce7c05335af801 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -64,6 +64,15 @@ def testDocumentAsyncAttr(self): self.assertFalse(doc.async_) self.assertFalse(Document.async_) + def testNodeValueDefaultOnBaseNode(self): + # gh-100710: nodeValue must be declared on the base Node class + # (not just on its subclasses) so that generic Node-typed code + # and static type checkers see the attribute. + self.assertIsNone(Node.nodeValue) + node = Node() + self.assertTrue(hasattr(node, 'nodeValue')) + self.assertIsNone(node.nodeValue) + def testParseFromBinaryFile(self): with open(tstfile, 'rb') as file: dom = parse(file) diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py index 16b33b90184dc5..330fd42d5c7fb8 100644 --- a/Lib/xml/dom/minidom.py +++ b/Lib/xml/dom/minidom.py @@ -37,6 +37,7 @@ class Node(xml.dom.Node): ownerDocument = None nextSibling = None previousSibling = None + nodeValue = None prefix = EMPTY_PREFIX # non-null only for NS elements and attributes diff --git a/Misc/NEWS.d/next/Library/2026-08-11-18-30-00.gh-issue-100710.6V5Prz.rst b/Misc/NEWS.d/next/Library/2026-08-11-18-30-00.gh-issue-100710.6V5Prz.rst new file mode 100644 index 00000000000000..87cab85525f40a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-08-11-18-30-00.gh-issue-100710.6V5Prz.rst @@ -0,0 +1,5 @@ +Add a class-level ``nodeValue`` default (``None``) to the base +:class:`!Node` class in :mod:`xml.dom.minidom`, matching the DOM +interface it implements. Every concrete subclass already sets +``nodeValue`` at runtime, so this only affects code and static type +checkers that reference a bare ``Node``-typed value.