-
Notifications
You must be signed in to change notification settings - Fork 476
Enable mypy for ddtrace core, add type hinting for context, monkey, span, provider, helpers #2180
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
Conversation
ddtrace/span.py
Outdated
| def duration(self, value): | ||
| self.duration_ns = value * 1e9 | ||
| # type: (int) -> None | ||
| self.duration_ns = value * 1e9 # 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.
* 1e9 turns duration_ns into a float; perhaps it's best to either cast 1e9 to int or spell out those zeroes (the former would be more readable)?
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 Gab, I learned something new today! 😮 I'll cast the duration_ns as an int in a separate PR but leave the type hinting as is here for now.
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.
This is actually an error!!
datadog-agent_1 | 2021-03-16 18:44:07 UTC | TRACE | ERROR | (pkg/trace/api/api.go:379 in handleTraces) | Cannot decode v0.4 traces payload: msgp: attempted to decode type "float64" with method for "int"
|
@Yun-Kim this pull request is now in conflict 😩 |
ddtrace/span.py
Outdated
|
|
||
| @duration.setter | ||
| def duration(self, value): | ||
| # type: (int) -> 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.
| # type: (int) -> None | |
| # type: (float) -> None |
Kyle-Verhoog
left a comment
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.
oops! forgot to hit submit yesterday 🤦
| """The span duration in seconds.""" | ||
| if self.duration_ns is not None: | ||
| return self.duration_ns / 1e9 | ||
| # TODO: add return None if self.duration_ns is 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.
This function returns None already in this case, so this comment can be removed
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.
Mypy wants an explicit return in the case self.duration_ns is None I believe, should be a quick fix in a separate PR
| self.log.log(level, msg) | ||
|
|
||
| def trace(self, name, service=None, resource=None, span_type=None): | ||
| # type: (str, Optional[str], Optional[str], Optional[Union[str, SpanTypes]]) -> Span |
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 this should be SpanTypes still
Description
Following #2163, the following files were type hinted for mypy:
Checklist