Skip to content

xml.etree.ElementTree Deprecation Warnings #419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
radoering opened this issue Apr 29, 2025 · 0 comments
Open

xml.etree.ElementTree Deprecation Warnings #419

radoering opened this issue Apr 29, 2025 · 0 comments

Comments

@radoering
Copy link

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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant