Use Element[Any] instead of Element in ElementTree#14198
Use Element[Any] instead of Element in ElementTree#14198srittau merged 7 commits intopython:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
|
I haven't looked too deeply into this, but I don't think changing the from xml.etree import ElementTree
tree = ElementTree.parse("foo.xml")
el = tree.find(".//*")
assert el is not None
print(type(el.tag))
This needs a more nuanced approach. I'm not sure what problems @JelleZijlstra alluded to in #14036, though. |
|
The problem is primarily in argument types, not return types. For example, the For return types, returning I'm becoming skeptical that the way we're using TypeVar defaults has been a good idea; it can lead to usability issues quite easily. |
| @overload | ||
| def get(self, key: str, default: _T) -> str | _T: ... | ||
| def insert(self, index: int, subelement: Element, /) -> None: ... | ||
| def insert(self, index: int, subelement: Element[Any], /) -> None: ... |
There was a problem hiding this comment.
because append accepts Element[Any] it seems appropriate to accept Element[Any] for insert, remove and __setitem__
This comment has been minimized.
This comment has been minimized.
As the person who added that part to the xml stubs, I believe my thought process was that tag is This particular issue came up because it seems like I didn't look at the uses of |
srittau
left a comment
There was a problem hiding this comment.
Thanks, and sorry for the delay.
|
stubtest errors are unrelated. |
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Resolves #14036