-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Major update for the xml module #13349
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
Not as much noise from mypy-primer as I feared. I'll take a look at those later. |
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.
The couple new errors in mypy-primer come from using |
This comment has been minimized.
This comment has been minimized.
It did work as expected; the remaining issue is the same but they're using defusedxml, which has it's own parse() method that is just annotated as returning It'd be better if the default was |
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]
+ 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[Any] | None], ElementTree[Element[str]]]", local name has type "Callable[[Any, DefusedXMLParser | None, bool, bool, bool], ElementTree[Element[str] | None]]") [assignment]
+ torchvision/datasets/voc.py:201: error: Argument 1 to "parse_voc_xml" of "VOCDetection" has incompatible type "Element[str] | None"; expected "Element[str]" [arg-type]
materialize (https://github.com/MaterializeInc/materialize)
- misc/python/materialize/cli/gen-chroma-syntax.py:56: error: Incompatible types in assignment (expression has type "Element | None", variable has type "Element") [assignment]
+ misc/python/materialize/cli/gen-chroma-syntax.py:56: error: Incompatible types in assignment (expression has type "Element[str] | None", variable has type "Element[str]") [assignment]
|
This MR adds typing for everything in the xml module, which had a lot of incomplete parts still.
I did this by taking a copy of the implementation, copying all of our current stubs inline, and then running
mypy --strict
on it and fixing all the (many, many) problems. I found a few very old bugs in the process: python/cpython#128302The implementation in this module is heavily duck-typed, and I've used generic in some possibly questionable ways to accommodate some of that; see some of my comments about it below. Otherwise, I think this is ready for review now.
Related to #6886.