Skip to content
New issue

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

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

Already on GitHub? # to your account

[xml] silence FutureWarning from lxml #2149

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

midichef
Copy link
Contributor

@midichef midichef commented Dec 3, 2023

Viewing an xml file gives this error:

/home/midichef/.local/lib/python3.10/site-packages/visidata/modify.py:51:
FutureWarning: The behavior of this method will change in future versions.
Use specific 'len(elem)' or 'elem is not None' test instead.

The warning relates to the surprising behavior of the truth value of lxml Element, which is the same as the truth value of a list of its children. That may not be what people expect when they do if lxml_element:. So lxml gives a FutureWarning in conditionals like that.

To silence the warning, I modified the colorizer function to test for r is not None instead of just r.
Is this the right way to test for a row? I'm not sure if there is another type of row where if r means more than if r is not None?

@saulpw
Copy link
Owner

saulpw commented Dec 3, 2023

Yes, it is. We need that because each colorizer is called for the column headers and column separators, but with row=None or col=None. (The colorizer API has always been a bit frustrating, maybe the CellColorizer could do the check for us.)

@midichef midichef marked this pull request as ready for review December 3, 2023 08:14
lxml elements, in a conditional, behave like a list of their children. An element with children evalutes to True, one with no children evaluates to False.
Because the behavior is surprising to people, lxml now gives FutureWarnings when the truth value of an Element is checked via "if lxml_elem:". See
https://lxml.de/tutorial.html#elements-are-lists
@midichef
Copy link
Contributor Author

midichef commented Dec 3, 2023

I just changed the commit message to say [xml-].

@anjakefala anjakefala merged commit e7aa1f7 into saulpw:develop Dec 4, 2023
@midichef midichef deleted the xml_futurewarning branch December 4, 2023 08:05
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants