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

HTTPResponse is not recognized as a subtype of typing.IO #2189

Closed
asottile opened this issue Jun 4, 2018 · 1 comment
Closed

HTTPResponse is not recognized as a subtype of typing.IO #2189

asottile opened this issue Jun 4, 2018 · 1 comment

Comments

@asottile
Copy link
Contributor

asottile commented Jun 4, 2018

Copied from python/mypy#3108

From SO:

request = urllib.request.Request(get_file_url, headers=self.data_api_headers)

with urllib.request.urlopen(request) as response:
    with open(export_file_path, 'wb') as out_file:

        shutil.copyfileobj(response, out_file)

This fails with Argument 1 to "copyfileobj" has incompatible type "Union[HTTPResponse, BinaryIO]"; expected IO[Any] because HTTPResponse derives from io.BufferedIOBase, which (despite being a binary IO) does not derive from typing.BinaryIO (nor does io.RawIOBase; also io.IOBase does not derive from typing.IO).

When I attempted to derive them as I thought would make sense, I got errors because __enter__ and other methods are defined both in io.IOBase and in typing.BinaryIO.

Not sure how to solve it.

@asottile
Copy link
Contributor Author

asottile commented Jun 4, 2018

From @ethanhs

This came up again in #2188 (comment) it seems.

JelleZijlstra added a commit to JelleZijlstra/typeshed that referenced this issue Jun 12, 2018
Fixes python#2189

The errors from mypy are a false positive (see python/mypy#5027).
gvanrossum pushed a commit that referenced this issue Jun 12, 2018
Fixes #2189.

The errors from mypy are a false positive (see python/mypy#5027).
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this issue Jan 23, 2019
Fixes python#2189.

The errors from mypy are a false positive (see python/mypy#5027).
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