-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add types for defusedxml #11179
Add types for defusedxml #11179
Conversation
from .ElementTree import ( | ||
DefusedXMLParser, | ||
ParseError as ParseError, | ||
fromstring as fromstring, | ||
iterparse as iterparse, | ||
parse as parse, | ||
tostring as tostring, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original source code has the following imports:
XMLTreeBuilder as XMLTreeBuilder
XMLParse as XMLParse
XMLParser as XMLParser
XML as XML
They were removed as Flake8 complained that below, they were being redefined, or that XML
could not be redefined because it's a constant. If this isn't right, let me know how I could improve this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: The current version of this file looks good, although you should probably add the __all__
statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@srittau added
This comment has been minimized.
This comment has been minimized.
6a721a7
to
b6ca295
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: vision (https://github.com/pytorch/vision)
+ torchvision/datasets/voc.py:10: error: Incompatible import of "ET_parse" (imported name has type "Callable[[int | str | bytes | PathLike[str] | PathLike[bytes] | SupportsRead[bytes] | SupportsRead[str], XMLParser | None], ElementTree]", local name has type "Callable[[Any, DefusedXMLParser | None, bool, bool, bool], ElementTree]") [assignment]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry for the late review. This looks good to me, although I didn't compare it to the implementation.
@srittau thank you for the review! I'll follow up with fixes once I implement this into my personal project |
@solkaz Thanks for putting this together! I noticed that I know this PR is already merged. I guess we need to create a new one? |
Indeed. Any PRs to further improve the stubs are welcome! |
Thanks for adding those types ! I got an error with the find function: import xml.etree.ElementTree as ET
import defusedxml.ElementTree as DET
el = DET.fromstring(filecontent)
subEl = el.find("Document", ns) Mypy gives the error: I can cast I am not sure where I should report this, let me know if there is a better place. |
@tyrossel, please open an issue on our tracker if there's a problem with these stubs; it's hard to keep track of comments on merged PRs :) |
Initial attempt at adding types for defusedxml.
Some notes:
xml.sax.expatreader
- undocumentedlxml
- no types, and I would prefer to ignore it for now