Repository navigation
Conversation
b0a9cac to
3c7fd1f
Compare
3c7fd1f to
1bbf754
Compare
| ciphers: list[str] | None = None, | ||
| use_netrc: bool | None = True, | ||
| context: ssl.SSLContext | None = None, | ||
| ) -> None: |
There was a problem hiding this comment.
Is it intentional to allow the params with defaults (use_proxy, force, timeout, etc) to allow None here? That would seem to nullify the effect of calling _fallback() to set the values in open(), no?
There was a problem hiding this comment.
None of the default values have changed, they should all be matching the git removal above this.
There was a problem hiding this comment.
It wasn't so much about the defaults changing, but more about being explicit that None is allowed. I didn't check any usages to see if we actually do that. It may not actually be a concern, just pointing it out.
There was a problem hiding this comment.
Pretty sure it's wrong for args with boolean defaults to have | None.
| ssl_handler = urllib.request.HTTPSHandler(context=context) | ||
| handlers.append(ssl_handler) | ||
| if HAS_SSL: | ||
| if unix_socket and UnixHTTPSHandler: |
There was a problem hiding this comment.
If adding the HAS_SSL check, might as well simplify to:
if HAS_SSL and unix_socket and UnixHTTPSHandler:
There was a problem hiding this comment.
I've removed that branch. I'm not sure what I was stuck up on before, but I don't seem to be getting a mypy error any longer.
| ) from e | ||
|
|
||
| return signature | ||
| return signature.decode('utf-8') |
There was a problem hiding this comment.
Perhaps, add type annotations to this function signature before making runtime changes? It's not being type-checked unless you do so. Let MyPy show where your change may possibly cause problems.
There was a problem hiding this comment.
It has type annotations, which is how I knew it caused an issue. It was that open_url didn't so it had no inference about what was being returned.
There was a problem hiding this comment.
Oh, I have a feeling that sometimes comment-based annotations don't work well. Have you checked it by introducing an intentional error?
This is what I'm worried about:
def get_signature_from_source(source, display=None): # type: (str, t.Optional[Display]) -> str| use_proxy: bool | None = True, | ||
| force: bool | None = False, | ||
| timeout: int | None = 10, | ||
| validate_certs: bool | None = True, | ||
| url_username: str | None = None, | ||
| url_password: str | None = None, | ||
| http_agent: str | None = None, | ||
| force_basic_auth: bool | None = False, | ||
| follow_redirects: _FollowRedirects | None = 'urllib2', | ||
| client_cert: str | None = None, | ||
| client_key: str | None = None, | ||
| cookies: cookiejar.CookieJar | None = None, | ||
| unix_socket: str | None = None, | ||
| ca_path: str | None = None, | ||
| unredirected_headers: list[str] | None = None, | ||
| decompress: bool | None = True, | ||
| ciphers: list[str] | None = None, | ||
| use_netrc: bool | None = True, |
There was a problem hiding this comment.
Usually, bool values mustn't have a union w/ None (except for when it's used as a sentinel or has defined semantics).
| use_proxy: bool | None = True, | |
| force: bool | None = False, | |
| timeout: int | None = 10, | |
| validate_certs: bool | None = True, | |
| url_username: str | None = None, | |
| url_password: str | None = None, | |
| http_agent: str | None = None, | |
| force_basic_auth: bool | None = False, | |
| follow_redirects: _FollowRedirects | None = 'urllib2', | |
| client_cert: str | None = None, | |
| client_key: str | None = None, | |
| cookies: cookiejar.CookieJar | None = None, | |
| unix_socket: str | None = None, | |
| ca_path: str | None = None, | |
| unredirected_headers: list[str] | None = None, | |
| decompress: bool | None = True, | |
| ciphers: list[str] | None = None, | |
| use_netrc: bool | None = True, | |
| use_proxy: bool = True, | |
| force: bool = False, | |
| timeout: int | None = 10, | |
| validate_certs: bool = True, | |
| url_username: str | None = None, | |
| url_password: str | None = None, | |
| http_agent: str | None = None, | |
| force_basic_auth: bool = False, | |
| follow_redirects: _FollowRedirects | None = 'urllib2', | |
| client_cert: str | None = None, | |
| client_key: str | None = None, | |
| cookies: cookiejar.CookieJar | None = None, | |
| unix_socket: str | None = None, | |
| ca_path: str | None = None, | |
| unredirected_headers: list[str] | None = None, | |
| decompress: bool = True, | |
| ciphers: list[str] | None = None, | |
| use_netrc: bool = True, |
| client_cert: str | None = None, | ||
| client_key: str | None = None, | ||
| cookies: cookiejar.CookieJar | None = None, | ||
| use_gssapi: bool | None = False, |
There was a problem hiding this comment.
| use_gssapi: bool | None = False, | |
| use_gssapi: bool = False, |
| use_proxy: bool | None = True, | ||
| force: bool | None = False, | ||
| last_mod_time: _datetime.datetime | None = None, | ||
| timeout: int | None = 10, | ||
| validate_certs: bool | None = True, | ||
| url_username: str | None = None, | ||
| url_password: str | None = None, | ||
| http_agent: str | None = None, | ||
| force_basic_auth: bool | None = False, | ||
| follow_redirects: _FollowRedirects | None = 'urllib2', | ||
| client_cert: str | None = None, | ||
| client_key: str | None = None, | ||
| cookies: cookiejar.CookieJar | None = None, | ||
| use_gssapi: bool | None = False, | ||
| unix_socket: str | None = None, | ||
| ca_path: str | None = None, | ||
| unredirected_headers: list[str] | None = None, | ||
| decompress: bool | None = True, | ||
| ciphers: list[str] | None = None, | ||
| use_netrc: bool | None = True, |
There was a problem hiding this comment.
| use_proxy: bool | None = True, | |
| force: bool | None = False, | |
| last_mod_time: _datetime.datetime | None = None, | |
| timeout: int | None = 10, | |
| validate_certs: bool | None = True, | |
| url_username: str | None = None, | |
| url_password: str | None = None, | |
| http_agent: str | None = None, | |
| force_basic_auth: bool | None = False, | |
| follow_redirects: _FollowRedirects | None = 'urllib2', | |
| client_cert: str | None = None, | |
| client_key: str | None = None, | |
| cookies: cookiejar.CookieJar | None = None, | |
| use_gssapi: bool | None = False, | |
| unix_socket: str | None = None, | |
| ca_path: str | None = None, | |
| unredirected_headers: list[str] | None = None, | |
| decompress: bool | None = True, | |
| ciphers: list[str] | None = None, | |
| use_netrc: bool | None = True, | |
| use_proxy: bool = True, | |
| force: bool = False, | |
| last_mod_time: _datetime.datetime | None = None, | |
| timeout: int | None = 10, | |
| validate_certs: bool = True, | |
| url_username: str | None = None, | |
| url_password: str | None = None, | |
| http_agent: str | None = None, | |
| force_basic_auth: bool = False, | |
| follow_redirects: _FollowRedirects | None = 'urllib2', | |
| client_cert: str | None = None, | |
| client_key: str | None = None, | |
| cookies: cookiejar.CookieJar | None = None, | |
| use_gssapi: bool = False, | |
| unix_socket: str | None = None, | |
| ca_path: str | None = None, | |
| unredirected_headers: list[str] | None = None, | |
| decompress: bool = True, | |
| ciphers: list[str] | None = None, | |
| use_netrc: bool = True, |
| use_gssapi: bool | None, | ||
| force_basic_auth: bool | None, | ||
| use_netrc: bool | None |
There was a problem hiding this comment.
Can these really be None in runtime?
SUMMARY
This PR adds type hints for
open_urland associated functions.ISSUE TYPE