-
-
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
Simplify Traversable.open() signature #10934
Conversation
This is necessary so that implentors can reasonanbly implement this method. For example `zipfile.Path.open()` (which is considered a `Traversable`) only supports this subset.
Closes: #10930 |
stdlib/importlib/abc.pyi
Outdated
encoding: str | None = None, | ||
errors: str | None = None, | ||
newline: str | None = None, | ||
) -> IO[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.
I wonder if we can make the return type a Protocol with a few common methods like read
. To get the exact signature, could look at how importlib uses Traversable internally.
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.
This was my long term plan (to get rid of IO
). But I don't want to look into this at this moment. Partly to keep this change small, partly because of laziness.
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.
Thanks for working on this! Worth adding a test that some path classes are importlib.abc.Traversable?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The argument is named differently in both `pathlib.Path` and `zipfile.Path`.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
After one or two short revisions, this is now working. |
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.
Nice, thank you!
This is necessary so that implentors can reasonably implement this method. For example
zipfile.Path.open()
(which is considered aTraversable
) only supports this subset.Closes #10930