classification
Title: minidom removeAttributeNode returns None
Type: enhancement Stage:
Components: Library (Lib), XML Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: iter, r.david.murray, terry.reedy
Priority: normal Keywords:

Created on 2018-04-13 18:36 by iter, last changed 2018-04-21 01:17 by iter.

Pull Requests
URL Status Linked Edit
PR 6462 open iter, 2018-04-13 18:36
Messages (3)
msg315253 - (view) Author: Ari Krupnik (iter) * Date: 2018-04-13 18:36
W3C DOM Level 1[1] requires removeAttributeNode() to return the removed node:

removeAttributeNode: Removes the specified attribute.
Return Value: The Attr node that was removed.

Minidom implementation returns None.

[1]https://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html#method-removeAttributeNode
msg315544 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-04-21 00:31
It is standard in the Python stdlib that mutation methods usually return None and never echo an input argument.  If one can pass a node to element.removeAttributeNode(node), there is no need to echo it back.  So I suspect that the current behavior is intended.

David, is there a general (perhaps unwritten) rule about how Python translates such functions?

The other 'remove' methods also default to returning None.  Same for the 'set' methods.  All methods would need review before changing just one.
msg315546 - (view) Author: Ari Krupnik (iter) * Date: 2018-04-21 01:17
I guess the main question if whether minidom wants to adhere to the standard or be pythonic, and it's not up to me to decide, although personally I like standards.

The common use case for DOM functions returning the relevant nodes is for the caller to chain calls, e.g.,

e1.setAttributeNode(e0.removeAttributeNode(e0.getAttributeNode("a")))

instead of

a=e0.getAttributeNode("foo")
e0.removeAttributeNode(a)
e1.setAttributeNode(a)
History
Date User Action Args
2018-04-21 01:17:50itersetmessages: + msg315546
2018-04-21 00:31:15terry.reedysetversions: - Python 2.7
nosy: + r.david.murray, terry.reedy

messages: + msg315544

type: behavior -> enhancement
2018-04-13 18:37:43itersettype: behavior
2018-04-13 18:36:43itercreate