Skip to content

Use protocol for GzipFile fileobj parameter #5099

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

Closed
jlost opened this issue Mar 8, 2021 · 1 comment · Fixed by #5170
Closed

Use protocol for GzipFile fileobj parameter #5099

jlost opened this issue Mar 8, 2021 · 1 comment · Fixed by #5170
Labels
stubs: false positive Type checkers report false errors topic: io I/O related issues

Comments

@jlost
Copy link

jlost commented Mar 8, 2021

sftp_client = paramiko.SFTPClient.from_transport(...)
out_gz = sftp_client.file(filename)
out = gzip.GzipFile(fileobj=out_gz, filename=filename)
                               ^
Argument of type "SFTPFile" cannot be assigned to parameter "fileobj" of type "IO[bytes] | None" in function "__init__"
  Type "SFTPFile" cannot be assigned to type "IO[bytes] | None"
    "SFTPFile" is incompatible with "IO[bytes]"
    Cannot assign to "None"

It seems like it should be compatible. Should I cast here? Any thoughts?

@srittau
Copy link
Collaborator

srittau commented Mar 8, 2021

GzipFile is still using IO as argument type, which is discouraged. We prefer custom protocols for argument types, and that would hopefully fix the problem above. Using cast() or # type: ignore is probably the best "quick" solution, until we land a proper fix in typeshed.

@srittau srittau changed the title Paramiko: "SFTPFile" is incompatible with "IO[bytes]" Use protocol for GzipFile fileobj parameter Apr 1, 2021
@srittau srittau added size-medium stubs: false positive Type checkers report false errors topic: io I/O related issues labels Apr 1, 2021
srittau added a commit to srittau/typeshed that referenced this issue Apr 1, 2021
JelleZijlstra pushed a commit that referenced this issue Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors topic: io I/O related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants