gh-100710: Add nodeValue default to xml.dom.minidom.Node base class - #155586
Open
SomSamantray wants to merge 2 commits into
Open
gh-100710: Add nodeValue default to xml.dom.minidom.Node base class#155586SomSamantray wants to merge 2 commits into
SomSamantray 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.
Author
|
@python-cla-bot check |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).