From f569957bbe047938a2d585bf58bbe96dede5301a Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Fri, 1 Mar 2019 16:08:26 -0800 Subject: [PATCH] Make urllib2.urlopen return a non-optional addinfourl (#2821) 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. --- stdlib/2/urllib2.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/2/urllib2.pyi b/stdlib/2/urllib2.pyi index bee73f1cc..3da0cd80c 100644 --- a/stdlib/2/urllib2.pyi +++ b/stdlib/2/urllib2.pyi @@ -52,9 +52,11 @@ class OpenerDirector(object): def open(self, fullurl: Union[Request, _string], data: Optional[_string] = ..., timeout: Optional[float] = ...) -> Optional[addinfourl]: ... def error(self, proto: _string, *args: Any): ... +# Note that this type is somewhat a lie. The return *can* be None if +# a custom opener has been installed that fails to handle the request. def urlopen(url: Union[Request, _string], data: Optional[_string] = ..., timeout: Optional[float] = ..., cafile: Optional[_string] = ..., capath: Optional[_string] = ..., cadefault: bool = ..., - context: Optional[ssl.SSLContext] = ...) -> Optional[addinfourl]: ... + context: Optional[ssl.SSLContext] = ...) -> addinfourl: ... def install_opener(opener: OpenerDirector) -> None: ... def build_opener(*handlers: Union[BaseHandler, Type[BaseHandler]]) -> OpenerDirector: ...