Skip to content

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

Closed

Description

@asottile

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.

Activity

  1. asottile commented on Jun 4, 2018

    @asottile
    ContributorAuthor

    From @ethanhs

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

  2. added a commit that references this issue on Jun 12, 2018
    5d16cac
  3. added a commit that references this issue on Jun 12, 2018
    de86f15
  4. added a commit that references this issue on Jan 23, 2019
    9668d31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions