Skip to content

xml.etree.ElementTree Deprecation Warnings #419

@radoering

Description

@radoering

I noticed the following deprecation warning when using odxtools with Python 3.12:

odxtools/specialdatagroup.py:25: DeprecationWarning: Testing an element's truth value will always return True in future versions.  Use specific 'len(elem)' or 'elem is not None' test instead.
    if caption_elem := et_element.find("SDG-CAPTION"):

which is caused by the following line:

if caption_elem := et_element.find("SDG-CAPTION"):

This can be fixed as follows:

-         if caption_elem := et_element.find("SDG-CAPTION"):
+         if (caption_elem := et_element.find("SDG-CAPTION")) is not None:

There are at least two more similar issues:

for elem in et_element.find("OUT-PARAM-IF-REFS") or []:

and

for elem in et_element.find("IN-PARAM-IF-REFS") or []:

which can be fixed similarly, e.g.:

-        for elem in et_element.find("IN-PARAM-IF-REFS") or []:
+        for elem in [] if (in_elems := et_element.find("IN-PARAM-IF-REFS")) is None else in_elems:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions