-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include additional files to be typed checks, up to exceptions.py #1931
Conversation
src/urllib3/exceptions.pyi
Outdated
|
||
class PoolError(HTTPError): | ||
pool: Any | ||
def __init__(self, pool: Any, message: str) -> None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pool
here is from connectionpool.py
, but importing here would create a circular dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're hitting circular imports you can sometimes use this construction:
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from urllib3.connectionpool import ConnectionPool
class PoolError:
pool: "ConnectionPool"
src/urllib3/exceptions.pyi
Outdated
class MaxRetryError(RequestError): | ||
reason: Any | ||
def __init__(self, pool: Any, url: str, reason=Optional[str]) -> None: ... # type: ignore | ||
|
||
class HostChangedError(RequestError): | ||
retries: Any | ||
def __init__(self, pool: Any, url: str, retries=int) -> None: ... # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little puzzled why I keep getting a mypy error here despite adding explicit types, so included an ignore.
src/urllib3/exceptions.pyi:25: error: Function is missing a type annotation for one or more arguments
src/urllib3/exceptions.pyi:29: error: Function is missing a type annotation for one or more arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be retries: int
instead of =int :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL I guess this is where I should have taken a break :D
Codecov Report
@@ Coverage Diff @@
## master #1931 +/- ##
==========================================
+ Coverage 99.77% 99.81% +0.04%
==========================================
Files 24 24
Lines 2179 2179
==========================================
+ Hits 2174 2175 +1
+ Misses 5 4 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this, here are some comments for you :)
I'm wondering about the empty .pyi
files, should we follow the dependency tree to commit type stubs for all the dependencies of a node before that node itself to not run into issues?
src/urllib3/exceptions.pyi
Outdated
|
||
class PoolError(HTTPError): | ||
pool: Any | ||
def __init__(self, pool: Any, message: str) -> None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're hitting circular imports you can sometimes use this construction:
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from urllib3.connectionpool import ConnectionPool
class PoolError:
pool: "ConnectionPool"
src/urllib3/exceptions.pyi
Outdated
|
||
class MaxRetryError(RequestError): | ||
reason: Any | ||
def __init__(self, pool: Any, url: str, reason=Optional[str]) -> None: ... # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be :Optional[...]
instead of =Optional[...]
, remove the # type: ignore
after verifying this works
src/urllib3/exceptions.pyi
Outdated
class LocationValueError(ValueError, HTTPError): ... | ||
|
||
class LocationParseError(LocationValueError): | ||
location: Any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we know location
is a str
from the constructor? Can change from Any
to str
src/urllib3/exceptions.py
Outdated
@@ -1,5 +1,5 @@ | |||
from __future__ import absolute_import | |||
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this # type: ignore
is temporary? Should we start by typing urllib3.packages.six
per the dependency tree?
Thank you for the comments! I think that resolves all the generic I admit I took the easy way out with |
@sethmlarson OK I took a stab at |
@sethmlarson My initial plan was to ping to see if you had any additional thoughts, but instead I added additional downstream files to I'll take another look tomorrow. The ones that I'm still a bit puzzled on how to stub are the ones like
|
Merged as #1937 instead. |
Addresses #1897, as per discussion in #1897 (comment).
This PR includes additional files to be typed checked, up to
exceptions.py
. Note that both the.py
and.pyi
files are included in the checks.In particular, the
.pyi
file fromtypeshed
forexceptions.py
are ported over and expanded to satisfy type checks.