-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add type hints to the logging context code. #8939
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Various clean-ups to the structured logging and logging context code. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,12 @@ class Measure: | |
def __init__(self, clock, name): | ||
self.clock = clock | ||
self.name = name | ||
parent_context = current_context() | ||
curr_context = current_context() | ||
if not curr_context: | ||
parent_context = None | ||
else: | ||
assert isinstance(curr_context, LoggingContext) | ||
parent_context = curr_context | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an actual behavior change -- are we expecting to measure things started by the sentinel context? Should we add a warning here about this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we're expecting it, but I certainly can't guarantee that we're not doing it. A warning might be a better first step. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well this assertion should never fire since |
||
self._logging_context = LoggingContext( | ||
"Measure[%s]" % (self.name,), parent_context | ||
) | ||
|
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.
LogRecord
instances can have properties dynamically added, but mypy doesn't seem to like that.