Enable mypy for ddtrace core, add type hinting for context, monkey, span, provider, helpers#2180
Conversation
| 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.
* 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.
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.
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 😩 |
|
|
||
| @duration.setter | ||
| def duration(self, value): | ||
| # type: (int) -> None |
There was a problem hiding this comment.
| # type: (int) -> None | |
| # type: (float) -> None |
Kyle-Verhoog
left a comment
There was a problem hiding this comment.
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.
This function returns None already in this case, so this comment can be removed
There was a problem hiding this comment.
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.
I think this should be SpanTypes still
Description
Following #2163, the following files were type hinted for mypy:
Checklist