This is technically wrong. The documentation states that:
"Note that None may be returned if no handler handles the request
(though the default installed global OpenerDirector uses
UnknownHandler to ensure this never happens)."
This is super marginal and making it optional causes a few dozen
errors in an internal dropbox code base.
* HTTP Handler class annotations for py2/urllib2 & py3/urllib.request
Add full annotations for the following classes:
* Python 2:
* `urllib2.AbstractHTTPHandler`
* `urllib2.HTTPHandler`
* `urllib2.HTTPsHandler`
* Python 3:
* `urllib.request.AbstractHTTPHandler`
* `urllib.request.HTTPHandler`
* `urllib.request.HTTPsHandler`
This information is largely undocumented, and was obtained by directly examining
the Python source code:
* Python 2 (v2.7.15) - https://github.com/python/cpython/blob/v2.7.15/Lib/urllib2.py#L1115-L1243
* Python 3 (v3.7.1) - https://github.com/python/cpython/blob/v3.7.1/Lib/urllib/request.py#L1224-L1364
`urllib2.AbstractHTTPHandler.do_open` takes as a parameter either
`HTTPConnection` or `HTTPSConnection`--one of the classes, not an instance of
either--and constructs an object using only a few of the parameters that either
constructor could use. `HTTPConnectionProtocol` in `stdlib/2/httplib.pyi`
follows a similar patten to `HTTPConnectionProtocol` added to
`stdlib/3/http/client.pyi` in pull request #2582 to describe the type of the
`http_class` that is passed to `do_open`.
All these attributes can be seen when using `dir(type)`.
In the future we should be discussing if certain methods on object (like
__eq__) should really be there. IMO this should be defined on type where it
actually also appears when using `dir`.
When we import typeshed internally at Dropbox, somehow the fact that
these files are all stubs gets lost (it's a long story...). This
causes errors like this:
.../stdlib/2/ast.pyi:6: error: Name 'typing' already defined (by an import)
The quickest way around this is to rename the import to _typing.
Give it enough information to determine that addinfourl
is iterable and that iteration and read methods return bytes.
Modeled after what is in stdlib/3/urllib/response.pyi after confirming
by looking at Python 2.7 stdlib code.
PR #2516 aimed to widen the accepted file argument to json.dump, but
since `IO` is invariant in its argument, it actually disallowed
passing binary files.