False positive: Remove this identity check; it will always be False


Product : Community Edition, Version 8.9.6 (build 50800)
Type of error : False positive
Language : Python
Library : standard xml.etree.ElementTree library
Error : Remove this identity check; it will always be False.
Sample code:

import xml.etree.ElementTree as ET

tree = ET.ElementTree()
if tree.getroot() is None:  # <- This causes a false positive

Why that’s not an error: tree.getroot() returns None if the root element is not provided, else the ET.Element object.

Thanks for your product!

Etienne Monier

Hi @emonier ,

Thank you a lot for reporting this!
I created SONARPY-1018 to take care of it.
I believe we will provide a fix for next SonarQube version (i.e. 9.5).

Andrea G.

1 Like

You’re welcome!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.