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

tarfile improvements #5492

Merged
merged 6 commits into from
May 19, 2021
Merged

tarfile improvements #5492

merged 6 commits into from
May 19, 2021

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented May 18, 2021

  • Use Literal for mode.
  • Don't explicitly derive from Iterable.
  • Use imports from collections.abc.
  • Partialy replace IO in TarFile.

More IO improvements are possible in the future:

  • Split into _ReadableFileobj and _WritableFileobj, depending on mode.
  • TarFile.bz2open() and .xzopen() still use IO. This depends on improving bz2.pyi and lzma.pyi respectively gaining protocols.
  • TarFile.open() and module-level open() still use IO. This could be improved using overloads.
  • Some other functions and methods still use IO.

Closes: #5491

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@srittau
Copy link
Collaborator Author

srittau commented May 18, 2021

GitHub Actions is having issues again. https://www.githubstatus.com/

@srittau
Copy link
Collaborator Author

srittau commented May 18, 2021

It passes now.

@JelleZijlstra
Copy link
Member

I need more time to look at this properly, but it feels like a shame if we don't switch tarfile.open to a protocol, since that's presumably the main API users would use; it's also the API being used in the linked issue.

@srittau
Copy link
Collaborator Author

srittau commented May 18, 2021

Good point about this not closing the linked issue. tarfile.open() (which is alias of tarfile.TarFile.open()) is certainly doable and should be done, but needs may overloads and protocols for lzma and bz2 to be fully typed.

@srittau
Copy link
Collaborator Author

srittau commented May 18, 2021

To clarify: If I find time to do more, I'd like to do it in a separate PR. And possibly work on lzma and bz2 first.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Looks good apart from one detail

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

poetry (https://github.com/python-poetry/poetry.git)
- poetry/console/commands/self/update.py:234: error: Argument "fileobj" to "TarFile" has incompatible type "GzipFile"; expected "Optional[IO[bytes]]"

@srittau srittau merged commit 1ea3d0f into python:master May 19, 2021
@srittau srittau deleted the tarfile-io branch May 19, 2021 08:13
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.

GzipFile not allowed for tarfile.open(fileobj=...)
2 participants