Add missing tarfile.open overload for writable objects#12117
Merged
srittau merged 2 commits intopython:mainfrom Jun 21, 2024
Merged
Add missing tarfile.open overload for writable objects#12117srittau merged 2 commits intopython:mainfrom
tarfile.open overload for writable objects#12117srittau merged 2 commits intopython:mainfrom
Conversation
tarfile.open overload for writable objects
This comment has been minimized.
This comment has been minimized.
Contributor
Author
|
Originally I had overloads for each literal combination, but had issues with MyPy due to the pipe operators in them, as python/mypy#17148 hasn't been released yet it seems. |
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
srittau
approved these changes
Jun 21, 2024
Collaborator
srittau
left a comment
There was a problem hiding this comment.
There still a bunch of possible modes missing, but this is a good first step, thanks!
tsibley
added a commit
to nextstrain/cli
that referenced
this pull request
Sep 5, 2024
This started failing recently with newer typeshed stubs for
tarfile.open() (and/or newer stubs for requests.Response?).
mypy fails with:
nextstrain/cli/runner/conda.py:220: error: Argument "fileobj" to "open" has incompatible type "Union[HTTPResponse, Any]"; expected "Optional[IO[bytes]]"
and pyright with:
nextstrain/cli/runner/conda.py:220:14 - error: No overloads for "open" match the provided arguments (reportCallIssue)
nextstrain/cli/runner/conda.py:220:58 - error: Argument of type "Literal['r|*']" cannot be assigned to parameter "mode" of type "_FileCreationModes" in function "open"
Type "Literal['r|*']" is not assignable to type "_FileCreationModes"
"Literal['r|*']" is not assignable to type "Literal['a']"
"Literal['r|*']" is not assignable to type "Literal['w']"
"Literal['r|*']" is not assignable to type "Literal['x']" (reportArgumentType)
I'm guessing the difference is because they match the different
overloads of tarfile.open().
I dug into it a little¹, but the stubs here seem a bit scattershot at
the moment so I stopped and went with an ignore. An alternative fix is
casting response.raw to BinaryIO, but that seemed uglier and worse than
an ignore.
¹ See <python/typeshed#12117> (implicated)
and <python/typeshed#12181> (open, may fix?)
and <python/typeshed#12182> (open, may fix?)
tsibley
added a commit
to nextstrain/cli
that referenced
this pull request
Sep 5, 2024
This started failing recently with newer typeshed stubs for
tarfile.open() (and/or newer stubs for requests.Response?).
mypy fails with:
nextstrain/cli/runner/conda.py:220: error: Argument "fileobj" to "open" has incompatible type "Union[HTTPResponse, Any]"; expected "Optional[IO[bytes]]"
and pyright with:
nextstrain/cli/runner/conda.py:220:14 - error: No overloads for "open" match the provided arguments (reportCallIssue)
nextstrain/cli/runner/conda.py:220:58 - error: Argument of type "Literal['r|*']" cannot be assigned to parameter "mode" of type "_FileCreationModes" in function "open"
Type "Literal['r|*']" is not assignable to type "_FileCreationModes"
"Literal['r|*']" is not assignable to type "Literal['a']"
"Literal['r|*']" is not assignable to type "Literal['w']"
"Literal['r|*']" is not assignable to type "Literal['x']" (reportArgumentType)
I'm guessing the difference is because they match the different
overloads of tarfile.open().
I dug into it a little¹, but the stubs here seem a bit scattershot at
the moment so I stopped and went with an ignore. An alternative fix is
casting response.raw to BinaryIO, but that seemed uglier and worse than
an ignore.
¹ See <python/typeshed#12117> (implicated)
and <python/typeshed#12181> (open, may fix?)
and <python/typeshed#12182> (open, may fix?)
1 task
max-muoto
added a commit
to max-muoto/typeshed
that referenced
this pull request
Sep 8, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix issues detailed in #5491 by adding an appropiate overload when the tar file is being opened in a write mode.