Skip to content

Commit 6d441a1

Browse files
ref(scope): Properly type Scope.root_span
Currently, this property has type `Any`, but it can now be changed to `Optional[Span]` Depends on: - #4263
1 parent b30574a commit 6d441a1

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

sentry_sdk/integrations/huey.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@ def _capture_exception(exc_info):
110110
# type: (ExcInfo) -> None
111111
scope = sentry_sdk.get_current_scope()
112112

113-
if exc_info[0] in HUEY_CONTROL_FLOW_EXCEPTIONS:
114-
scope.root_span.set_status(SPANSTATUS.ABORTED)
115-
return
113+
if scope.root_span is not None:
114+
if exc_info[0] in HUEY_CONTROL_FLOW_EXCEPTIONS:
115+
scope.root_span.set_status(SPANSTATUS.ABORTED)
116+
return
117+
118+
scope.root_span.set_status(SPANSTATUS.INTERNAL_ERROR)
116119

117-
scope.root_span.set_status(SPANSTATUS.INTERNAL_ERROR)
118120
event, hint = event_from_exception(
119121
exc_info,
120122
client_options=sentry_sdk.get_client().options,
@@ -135,8 +137,10 @@ def _sentry_execute(*args, **kwargs):
135137
exc_info = sys.exc_info()
136138
_capture_exception(exc_info)
137139
reraise(*exc_info)
138-
else:
139-
sentry_sdk.get_current_scope().root_span.set_status(SPANSTATUS.OK)
140+
141+
root_span = sentry_sdk.get_current_scope().root_span
142+
if root_span is not None:
143+
root_span.set_status(SPANSTATUS.OK)
140144

141145
return result
142146

sentry_sdk/scope.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,7 @@ def fingerprint(self, value):
689689

690690
@property
691691
def root_span(self):
692-
# type: () -> Any
693-
# would be type: () -> Optional[Span], see https://github.com/python/mypy/issues/3004
692+
# type: () -> Optional[Span]
694693
"""Return the root span in the scope, if any."""
695694

696695
# there is no span/transaction on the scope

0 commit comments

Comments
 (0)