-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
stubs: false positiveType checkers report false errorsType checkers report false errors
Description
To Reproduce
import xml.etree.ElementTree as ET
parser = ET.XMLParser(target=ET.TreeBuilder(insert_comments=True))
doc = ET.ElementTree().parse("foo.xml", parser)
for el in doc.findall("*"):
if el.tag is ET.Comment: # error: Non-overlapping identity check (left operand type: "str", right operand type: "Callable[[str | None], Element[Callable[..., Element[Any]]]]") [comparison-overlap]
print("Comment:", x.text)
Expected Behavior
el.tag
should be allowed to be compared to ET.Comment
Actual Behavior
el.tag
is constrained to str
only and raises following comparision-overlap
error when compared with ET.Comment
:
# error: Non-overlapping identity check (left operand type: "str", right operand type: "Callable[[str | None], Element[Callable[..., Element[Any]]]]") [comparison-overlap]
This error started after upgrading from mypy 1.14 to 1.15, most likely caused by #13349
Tbh this isn't exactly documented behaviour and parsing comments programmatically isn't exactly best practice either, but some times you are not in control of the xmls received and reading the tag is the the only way to identify the comments that i know.
Your Environment
- Mypy version used: 1.17
- Mypy command-line flags:
mypy --strict test.py
- Python version used: 3.13
Metadata
Metadata
Assignees
Labels
stubs: false positiveType checkers report false errorsType checkers report false errors