-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Update xml.sax.parse to accept StrPath
#9708
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
Conversation
It appears to support `os.PathLike[str]` in addition to just `str`, based on trying it with `pathlib.Path` and a custom class implementing `__fspath__`.
This comment has been minimized.
This comment has been minimized.
|
I also found this, which supports making this change to the annotation |
|
Thanks! I just tested it on Python 3.7 and 3.8 and it seems not to work with 3.7 (but with 3.8). Could you add a |
stdlib/xml/sax/__init__.pyi
Outdated
|
|
||
| def parse( | ||
| source: str | _SupportsReadClose[bytes] | _SupportsReadClose[str], handler: ContentHandler, errorHandler: ErrorHandler = ... | ||
| source: StrPath | _SupportsReadClose[bytes] | _SupportsReadClose[str], |
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.
Shouldn't source also take xmlreader.InputSource ? source is coerced into an InputSource and the docstring also seems to imply one can be passed directly.
https://github.com/python/cpython/blob/3.11/Lib/xml/sax/saxutils.py#L338
https://github.com/python/cpython/blob/3.11/Lib/xml/sax/expatreader.py#L105
https://github.com/python/cpython/blob/3.11/Lib/xml/sax/xmlreader.py#L117
@srittau Dunno if you wanna consider this outside the scope of this PR, because the type for parameter source is missing in a few locations. But I wanted to at least raise this.
Source to confirm your suspicions: https://github.com/python/cpython/blob/3.7/Lib/xml/sax/saxutils.py#L339 |
|
@srittau Can do! |
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
It appears to support
os.PathLike[str]in addition to juststr, based on trying it withpathlib.Pathand a custom class implementing__fspath__.