Title: is not labeled as read-only
Type: Stage: needs patch
Components: Documentation, Library (Lib), XML Versions: Python 3.8, Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: cheryl.sabella, dillona, docs@python, epicfaace, ezio.melotti, scoder, terry.reedy, urjitsb87
Priority: normal Keywords: easy

Created on 2011-10-08 04:18 by dillona, last changed 2019-04-14 14:14 by scoder.

Messages (8)
msg145155 - (view) Author: Dillon Amburgey (dillona) Date: 2011-10-08 04:18 does not label the name attribute as read-only (like localName) even though it is.
msg145156 - (view) Author: Dillon Amburgey (dillona) Date: 2011-10-08 04:19
The behavior can be verified as follows. Notice that despite changing the value, the output XML does not change

>>> from xml.dom import minidom, Node
>>> a = minidom.parseString("<a href=\"\">asd</a>")
>>> a
<xml.dom.minidom.Document instance at 0x22d7c68>
>>> a.childNodes
[<DOM Element: a at 0x22d7d88>]
>>> a.childNodes[0]
<DOM Element: a at 0x22d7d88>
>>> a.childNodes[0].attributes
<xml.dom.minidom.NamedNodeMap object at 0x21caa70>
>>> a.childNodes[0].attributes.item(0)
<xml.dom.minidom.Attr instance at 0x22d7f38>
>>> a.childNodes[0].attributes.item(0).name
>>> attr = a.childNodes[0].attributes.item(0)
>>> = "ad"
>>> a.toxml()
u'<?xml version="1.0" ?><a href="">asd</a>'
>>> attr.value = "asd"
>>> a.toxml()
u'<?xml version="1.0" ?><a href="asd">asd</a>'
msg145282 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-10-09 21:48
localName is defined with defproperty() in Lib/xml/dom/ and looking at the definition of defproperty() in  Lib/xml/dom/ I think this is supposed to raise an xml.dom.NoModificationAllowedErr exception when someone tries to write on the attribute.  This doesn't seem to happen though.
OTOH 'name' doesn't use defproperty(), so technically it's writable, expect that writing on it has no effect.
This should still be documented, and it would also be good to figure out what's going on with defproperty().
msg145567 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-10-14 22:27
The docs are unchanged in 3.2. I presume the behavior is also.
msg148788 - (view) Author: Urjit Bhatia (urjitsb87) Date: 2011-12-03 09:56
Using the same code example as above, I added a simple print statement in the set method being defined in the defproperty and it fired correctly for -

**My print statement:**in defproperty set for name: attributes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/urjit/code/mercurial/python/cpython/Lib/xml/dom/", line 106, in set
    "attempt to modify read-only attribute " + repr(name))
xml.dom.NoModificationAllowedErr: attempt to modify read-only attribute 'attributes'

The getter seems to work fine for localName but the setter somehow does not fire.

I have a fix for this but when I am running the test on my ubuntu vm, it doesnt go beyond test_sndhdr. However, when I run that test directly, it is successful. I can submit a patch if this problem is fixed.
msg333081 - (view) Author: Ashwin Ramaswami (epicfaace) * Date: 2019-01-05 23:18
This behavior appears to be working as expected per the documentation when using Python 3.7.1. I am able to change name, but changing localName gives me a NoModificationAllowedErr error.
msg340206 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-04-14 13:11

Do you think this should be documented?
msg340211 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2019-04-14 14:14
The intended interface seems to be to change .name rather than .localName, so yes, that should be documented somewhere.

The implementation seems a bit funny in that a "self._localName", if set, takes precedence, but there doesn't seem to be an official way to set it. The Attr() constructor even takes a "localname" argument, which it then ignores. o_O
Date User Action Args
2019-04-14 14:14:24scodersetstage: test needed -> needs patch
messages: + msg340211
components: + XML
versions: + Python 3.8
2019-04-14 13:11:34cheryl.sabellasetnosy: + cheryl.sabella, scoder
messages: + msg340206
2019-01-05 23:18:26epicfaacesetnosy: + epicfaace

messages: + msg333081
versions: + Python 3.7, - Python 2.7, Python 3.2, Python 3.3
2011-12-03 09:56:30urjitsb87setnosy: + urjitsb87
messages: + msg148788
2011-10-14 22:27:24terry.reedysetnosy: + terry.reedy

messages: + msg145567
versions: + Python 3.2, Python 3.3
2011-10-09 21:48:41ezio.melottisetcomponents: + Library (Lib)
versions: + Python 2.7
keywords: + easy
nosy: + ezio.melotti

messages: + msg145282
stage: test needed
2011-10-08 04:19:34dillonasetmessages: + msg145156
2011-10-08 04:18:11dillonacreate