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

GzipFile not allowed for tarfile.open(fileobj=...) #5491

Closed
asottile opened this issue May 18, 2021 · 5 comments · Fixed by #5492
Closed

GzipFile not allowed for tarfile.open(fileobj=...) #5491

asottile opened this issue May 18, 2021 · 5 comments · Fixed by #5492
Labels
topic: io I/O related issues

Comments

@asottile
Copy link
Contributor

minimal reproduction:

import gzip
import tarfile


open('t', 'w').close()
with gzip.GzipFile('out.tar.gz', 'wb') as gzipf:
    with tarfile.open(fileobj=gzipf, mode='w') as tf:
        tf.add('t')
$ python3 t.py 
$ mypy t.py
t.py:7: error: Argument "fileobj" to "open" has incompatible type "GzipFile"; expected "Optional[IO[bytes]]"
Found 1 error in 1 file (checked 1 source file)
$ mypy --version
mypy 0.812

presumably fileobj should use a Protocol of some shape ?

@hauntsaninja
Copy link
Collaborator

I think this just got fixed in #5099

@asottile
Copy link
Contributor Author

appears not fixed:

$ mypy --custom-typeshed-dir /tmp/typeshed/ t.py 
t.py:7: error: Argument "fileobj" to "open" has incompatible type "GzipFile"; expected "Optional[IO[bytes]]"
Found 1 error in 1 file (checked 1 source file)
$ mypy --version
mypy 0.820+dev.675ae1afc8a5b0a9a515292c7e9d6bc2a38887be
$ git -C ../typeshed/ rev-parse HEAD
7d4ecf7f0a64cbfab59e54c8df1d5c53bcd9b9a1

@emmatyping
Copy link
Contributor

It looks like #5170 fixed GzipFile, but not tarfile.

@JelleZijlstra JelleZijlstra reopened this May 18, 2021
@srittau srittau added the topic: io I/O related issues label May 18, 2021
@JelleZijlstra
Copy link
Member

As discussed the PR doesn't fix this issue, which is about tarfile.open. We still need to convert tarfile.open to overloads + IO protocols.

@max-muoto
Copy link
Contributor

We should be able to close this out now @JelleZijlstra.

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.

6 participants