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

Spurious typecheck failure when passing Gzipfile instance to tarfile.open #13135

Open
ncoghlan opened this issue Nov 27, 2024 · 1 comment · May be fixed by #13177
Open

Spurious typecheck failure when passing Gzipfile instance to tarfile.open #13135

ncoghlan opened this issue Nov 27, 2024 · 1 comment · May be fixed by #13177
Labels
topic: io I/O related issues

Comments

@ncoghlan
Copy link
Contributor

ncoghlan commented Nov 27, 2024

Due to #2580, the following code reports a typechecking error:

# Storage creation is conditional in the real code, hence `... | None` in the error message
storage = GzipFile(archive_name, mode="w", mtime=0)
tar = tarfile.open(archive_name, tar_mode, fileobj=storage)
error: Argument "fileobj" to "open" has incompatible type "GzipFile | None"; expected "IO[bytes] | None"  [arg-type]

The comments on #2580 suggested that tarfile.open should be migrated over to protocol checking instead, but I'm not sure what that actually looks like for IO[bytes].

@AlexWaygood AlexWaygood added the topic: io I/O related issues label Nov 27, 2024
@srittau srittau linked a pull request Dec 3, 2024 that will close this issue
@srittau
Copy link
Collaborator

srittau commented Dec 3, 2024

It seems that we already have a protocol _Fileobj, but we missed to replace a few instance in the open() annotations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: io I/O related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants