[issue46798] xml.etree.ElementTree: get() doesn't return default value, always ATTLIST value

2022-02-19 Thread padremayi


New submission from padremayi :

XML test file:









]>



This is a simple object
2022
Myself




Python code:
import xml.etree.ElementTree


try:
xml_data = xml.etree.ElementTree.iterparse("test.xml", events=("start", 
"end"))

for event, xml_tag in xml_data:
if event == "end" and xml_tag.tag == "object":
object_name = xml_tag.get("name")
object_description = xml_tag.find("description").text
works = xml_tag.get("works", default="foo")

print("works value: " + str(works))

xml_tag.clear()

print("Done!")

except (NameError, xml.etree.ElementTree.ParseError):
print("XML error!")


Output:
works value: yes
Done!


Expected behaviour:
works value: foo
Done!

--
components: XML
messages: 413543
nosy: padremayi
priority: normal
severity: normal
status: open
title: xml.etree.ElementTree: get() doesn't return default value, always 
ATTLIST value
type: behavior
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue46798>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46798] xml.etree.ElementTree: get() doesn't return default value, always ATTLIST value

2022-02-23 Thread padremayi


padremayi  added the comment:

IMHO if the developer doesn't manage the XML itself it is VERY unreasonable to 
use the document value and not the developer one. At the moment the developer 
must predict the future changes on XML structure.

For my point of view if an attribute is not present get() must return None (or 
the default value passed by developer) AND the document default adding an 
optional parameter to get() call: if True return 2 values, otherwise return the 
document one (current behaviour).

In this way the old code continue to work

--

___
Python tracker 
<https://bugs.python.org/issue46798>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46798] xml.etree.ElementTree: get() doesn't return default value, always ATTLIST value

2022-02-23 Thread padremayi


Change by padremayi :


--
status: closed -> open

___
Python tracker 
<https://bugs.python.org/issue46798>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46798] xml.etree.ElementTree: get() doesn't return default value, always ATTLIST value

2022-02-23 Thread padremayi


padremayi  added the comment:

Now:
def get(self, key, default=None)

Future:
def get(self, key, default=None, double_value=False)

No code break

--

___
Python tracker 
<https://bugs.python.org/issue46798>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com