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.
* The 'Running the tests' section suggests setting PYTHONPATH instead of MYPYPATH when testing typeshed as a submodule of mypy
* actually PYTHONPATH was the right var to set ... but it was set slightly wrong after a directory reshuffle
* local_addr and server_hostname are optional and default to None.
* If sock is given, none of host, port, family, proto, flags and
local_addr should be specified.
This gets imported from `_ast`, so the definition was
redundant. This causes problems with the new mypy semantic
analyzer, as it will flag the redefinition as an error.
`dispatch_request` can accept arbitrary arguments and can return
different values. To keep this simple and in line with the rest of the
stubs (e.g. with `view_func: Callable[..., Any]`), `Any` is used for the
return value although it is too broad.
Closes#2795.
* 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`.
* default_exceptions is a dict of classes, not instances
* Correctly overload 'redirect' to get the proper return type
* Request.get_data() is an Any (not bytes), just like Response.get_data
The python3 charset stubs didn't include certain necessary module level
constansts (like `QP`) and wrongly defined the arguments to some of
the functions in the module. This is no longer the case.
Fixes#2767
Currently, iter_lines() doesn't have any type annotations despite the types being very similar to iter_content and the types can be pretty readily derived from the source.