-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix additional type hints #9543
Changes from all commits
1fa08f4
3ca2ea3
f901773
76f9ebe
16bfe75
2b22d4c
2325c73
16ebad3
6d913a0
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 @@ | ||
Fix incorrect type hints. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -669,7 +669,7 @@ def g(*args, **kwargs): | |
return g | ||
|
||
|
||
def run_in_background(f, *args, **kwargs): | ||
def run_in_background(f, *args, **kwargs) -> defer.Deferred: | ||
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 think this isn't 100% true actually since if the result is not a 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. Yeah, probably. I don't think we should lie about our return value here. 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 wrapped the raw return value in |
||
"""Calls a function, ensuring that the current context is restored after | ||
return from the function, and that the sentinel context is set once the | ||
deferred returned by the function completes. | ||
|
@@ -697,8 +697,10 @@ def run_in_background(f, *args, **kwargs): | |
if isinstance(res, types.CoroutineType): | ||
res = defer.ensureDeferred(res) | ||
|
||
# At this point we should have a Deferred, if not then f was a synchronous | ||
# function, wrap it in a Deferred for consistency. | ||
if not isinstance(res, defer.Deferred): | ||
return res | ||
return defer.succeed(res) | ||
|
||
if res.called and not res.paused: | ||
# The function should have maintained the logcontext, so we can | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ class ToTwistedHandler(logging.Handler): | |
def emit(self, record): | ||
log_entry = self.format(record) | ||
log_level = record.levelname.lower().replace("warning", "warn") | ||
self.tx_log.emit( | ||
self.tx_log.emit( # type: ignore | ||
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. For some reason mypy things that 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 suspect this is fixed by twisted/twisted#1541? |
||
twisted.logger.LogLevel.levelWithName(log_level), "{entry}", entry=log_entry | ||
) | ||
|
||
|
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 things that one of these doesn't match the type signature for
logger.error
, but empirically it works...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.
@richvdh do you remember why we can't just use
logger.exception
here?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.
er we probably can just
s/error/exception/
, if that helps, though I don't think it will.or is your question why we pass in an explicit
exc_info
rather than lettinglogging
pull it fromsys.exc_info()
? in which case the answer is thatf.getTracebackObject
has magic to build a more useful stacktrace in the face of async execution. (It's possible that it's better nowadays with properasync/await
, but I suspect it's not.)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 background! I think leaving the ignore here is the best way forward at the moment without getting into a rabbit hole of logging.