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 wrong-arg-types; gzip.GzipFile not recognized as satisfying _typeshed.SupportsWrite[bytes] #1742

Open
nathanielmanistaatgoogle opened this issue Aug 25, 2024 · 0 comments

Comments

@nathanielmanistaatgoogle
Copy link
Member

Over in this area of python.org we see the sample program

import gzip
import shutil
with open('/home/joe/file.txt', 'rb') as f_in:
    with gzip.open('/home/joe/file.txt.gz', 'wb') as f_out:
        shutil.copyfileobj(f_in, f_out)

When I throw pytype (version 2024.4.11) at this sample program, type-checking fails with

File "/Users/nathaniel/temp-2023-08-25-pytype/haha.py", line 5, in <module>: Function shutil.copyfileobj was called with the wrong arguments [wrong-arg-types]
         Expected: (fsrc, fdst: _typeshed.SupportsWrite[bytes], ...)
  Actually passed: (fsrc, fdst: gzip.GzipFile)
  
  Method write of protocol _typeshed.SupportsWrite[AnyStr] has the wrong signature in gzip.GzipFile:
  
  >> _typeshed.SupportsWrite[AnyStr] expects:
  def write(self: _typeshed.SupportsWrite[_T_contra], __s: _T_contra) -> object: ...
  
  >> gzip.GzipFile defines:
  def write(self: gzip.GzipFile, data: Buffer) -> int: ...

For more details, see https://google.github.io/pytype/errors.html#wrong-arg-types

Type-checking this sample program ought pass, right?

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

No branches or pull requests

1 participant