-
Notifications
You must be signed in to change notification settings - Fork 801
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
Add type annotations to everything referenced in __init__.py #771
Conversation
def _make_handler( | ||
url: str, | ||
method: str, | ||
timeout: Optional[float], |
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.
Seems fine to me, but most cases where I see Optional
, there is typically a default of =None
; but in this case I guess the caller of this is explicitly required to pass in an explicit 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.
Yeah, this one is an internal and requires that we explicitly pass timeout though even if the value is None (or a default value) from one of the other handlers. A bit unusual I agree.
prometheus_client/exposition.py
Outdated
gateway: str, | ||
job: str, | ||
registry: CollectorRegistry, | ||
grouping_key: Optional[Dict[str, 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 grouping key is reused below, if it has a constant structure, may want to use a TypedDict
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 don't think it it has a constant structure, and TypedDict
isn't available earlier than 3.8 anyway :(. I really want to use Protocol
in a few places as well but cannot yet.
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.
It looks like you can use typing-extensions for TypedDict
and Protocol
.
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 have been avoiding adding typing-extensions as a dependency (we have no dependencies now), but if it becomes too painful I would considering adding it.
job: str, | ||
registry: CollectorRegistry, | ||
grouping_key: Optional[Dict[str, str]] = None, | ||
timeout: Optional[float] = 30, |
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.
here timeout has a default.
@@ -169,10 +201,17 @@ def __init__(self, name, documentation, count_value=None, sum_value=None, labels | |||
if labels is None: | |||
labels = [] | |||
self._labelnames = tuple(labels) |
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.
maybe self._labelnames = tuple(labels) if labels else ()
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.
Decent idea as a future cleanup, going to leave it out of this PR to keep the focus on types clear :).
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 so much!
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 the review!
prometheus_client/exposition.py
Outdated
gateway: str, | ||
job: str, | ||
registry: CollectorRegistry, | ||
grouping_key: Optional[Dict[str, 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.
I don't think it it has a constant structure, and TypedDict
isn't available earlier than 3.8 anyway :(. I really want to use Protocol
in a few places as well but cannot yet.
def _make_handler( | ||
url: str, | ||
method: str, | ||
timeout: Optional[float], |
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.
Yeah, this one is an internal and requires that we explicitly pass timeout though even if the value is None (or a default value) from one of the other handlers. A bit unusual I agree.
@@ -169,10 +201,17 @@ def __init__(self, name, documentation, count_value=None, sum_value=None, labels | |||
if labels is None: | |||
labels = [] | |||
self._labelnames = tuple(labels) |
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.
Decent idea as a future cleanup, going to leave it out of this PR to keep the focus on types clear :).
28bc122
to
60bc25d
Compare
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
60bc25d
to
7790582
Compare
Also update built in collectors to use the new Abstract Base Class. Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
7790582
to
35a48c2
Compare
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
35a48c2
to
b3a00ea
Compare
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
f277116
to
c350e5c
Compare
Fixes: #760
This should cover most of the public surface area used by others. There is more typing work to be done before we can enable stricter types, but this will be a good next step.