Skip to content
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

Merged
merged 18 commits into from
Oct 26, 2023
Merged

Simplify Traversable.open() signature #10934

merged 18 commits into from
Oct 26, 2023

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented Oct 26, 2023

This is necessary so that implentors can reasonably implement this method. For example zipfile.Path.open() (which is considered a Traversable) only supports this subset.

Closes #10930

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.
@srittau
Copy link
Collaborator Author

srittau commented Oct 26, 2023

Closes: #10930

encoding: str | None = None,
errors: str | None = None,
newline: str | None = None,
) -> IO[str]: ...
Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a 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?

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@srittau srittau marked this pull request as ready for review October 26, 2023 19:06
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau
Copy link
Collaborator Author

srittau commented Oct 26, 2023

After one or two short revisions, this is now working.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you!

@srittau srittau merged commit 1c184fe into python:main Oct 26, 2023
67 checks passed
@srittau srittau deleted the traversible branch October 26, 2023 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zipfile.Path is not understood by type checkers as a subtype of importlib.abc.Traversable
4 participants