gh-100710: Add nodeValue default to xml.dom.minidom.Node base class - #155586
gh-100710: Add nodeValue default to xml.dom.minidom.Node base class#155586SomSamantray wants to merge 2 commits into
Conversation
…lass 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.
|
@python-cla-bot check |
|
The addition itself is fine: it matches the other defaults on But nothing changes at runtime, so there is nothing to announce in NEWS. And the reported problem is already solved for type checkers: typeshed declares Please remove the test and the NEWS entry. The redundant definitions in the subclasses also can be removed -- |
Fixes gh-100710.
Node.nodeValueis documented per the DOM interface it implements, but the baseNodeclass inLib/xml/dom/minidom.pynever declares it — only concrete subclasses (Element,DocumentFragment,DocumentType,Entity,Notation,Documentas a class attribute;Attr,ProcessingInstruction,CharacterDatavia a property) set it.At runtime this is harmless since every instantiable subclass already sets
nodeValue. The reported symptom is static analysis: code holding aNode-typed reference (e.g. iteratingchildNodestyped asNode) and accessing.nodeValuetriggers a false-positive "unknown member" error from type checkers like Pylance, because the attribute isn't declared on the base class.Fix
Add
nodeValue = Noneas a class-level default onNode, matching the existing pattern already used fornamespaceURI,parentNode,ownerDocument,nextSibling, andpreviousSibling.Testing
testNodeValueDefaultOnBaseNodeinLib/test/test_minidom.py, asserting the baseNodeclass (and a bareNode()instance) exposesnodeValueasNone.test_minidomsuite locally (132 tests, all passing).