Skip to content

Argument 1 to "load" has incompatible type "HTTPResponse"; expected IO[str] #3007

Closed
@lithammer

Description

@lithammer

Python v3.6
Mypy v0.501

# http.py
import http.client
import json

conn = http.client.HTTPConnection('example.com')
conn.request('GET', '/foobar.json')
response = conn.getresponse()
json.load(response)

Since response is a "file-like object" (i.e. has a .read() method). And json.load(fp, ...) operates on those according to the documentation ("Deserialize fp (a .read()-supporting file-like object containing a JSON document) to a Python object") I expect this to work.

$ mypy http.py
http.py:8: error: Argument 1 to "load" has incompatible type "HTTPResponse"; expected IO[str]

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