Skip to content

Commit 64cbaff

Browse files
Fix "indented block" linter error (#3468)
* fix: Fix mypy "indented block" error Fix this [mypy error](https://github.com/getsentry/sentry-python/actions/runs/10390581522/job/28771379618): ``` sentry_sdk/integrations/opentelemetry/potel_span_processor.py:149: error: expected an indented block after function definition on line 31 [syntax] ``` Honestly not sure why this change fixes the problem, maybe there is some bug in `mypy`. * fix: Fix other mypy syntax failures After fixing the previous mypy failure, mypy discovered more syntax problems, which this commit fixes. * fix: Correct typing in `potel_span_processor` Fixing the original mypy error broke the typing; this change fixes the typing.
1 parent 3f9e2d0 commit 64cbaff

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

sentry_sdk/integrations/opentelemetry/potel_span_processor.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from collections import deque, defaultdict
2+
from typing import cast
23

34
from opentelemetry.trace import format_trace_id, format_span_id
45
from opentelemetry.context import Context
@@ -145,7 +146,7 @@ def _root_span_to_transaction_event(self, span):
145146
"transaction_info": {"source": "custom"},
146147
"contexts": contexts,
147148
}
148-
) # type: Event
149+
)
149150

150151
return event
151152

@@ -154,7 +155,10 @@ def _span_to_json(self, span):
154155
if not span.context:
155156
return None
156157

157-
span_json = self._common_span_transaction_attributes_as_json(span)
158+
# This is a safe cast because dict[str, Any] is a superset of Event
159+
span_json = cast(
160+
"dict[str, Any]", self._common_span_transaction_attributes_as_json(span)
161+
)
158162
if span_json is None:
159163
return None
160164

@@ -184,14 +188,14 @@ def _span_to_json(self, span):
184188
return span_json
185189

186190
def _common_span_transaction_attributes_as_json(self, span):
187-
# type: (ReadableSpan) -> Optional[dict[str, Any]]
191+
# type: (ReadableSpan) -> Optional[Event]
188192
if not span.start_time or not span.end_time:
189193
return None
190194

191195
common_json = {
192196
"start_timestamp": convert_from_otel_timestamp(span.start_time),
193197
"timestamp": convert_from_otel_timestamp(span.end_time),
194-
} # type: dict[str, Any]
198+
} # type: Event
195199

196200
measurements = extract_span_attributes(span, SentrySpanAttribute.MEASUREMENT)
197201
if measurements:

sentry_sdk/integrations/opentelemetry/scope.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ def _get_current_scope(cls):
4343

4444
@classmethod
4545
def get_isolation_scope(cls):
46+
# type: () -> Scope
4647
"""
4748
Returns the isolation scope.
4849
"""
49-
# type: () -> Scope
5050
return cls._get_isolation_scope() or _INITIAL_ISOLATION_SCOPE
5151

5252
@classmethod

sentry_sdk/scope.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,8 @@ def span(self):
770770

771771
@span.setter
772772
def span(self, span):
773-
"""Set current tracing span."""
774773
# type: (Optional[Span]) -> None
774+
"""Set current tracing span."""
775775
self._span = span
776776
# XXX: this differs from the implementation in JS, there Scope.setSpan
777777
# does not set Scope._transactionName.

sentry_sdk/tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ def sampled(self):
13641364

13651365
@sampled.setter
13661366
def sampled(self, value):
1367-
# type: () -> Optional[bool]
1367+
# type: (Optional[bool]) -> None
13681368
pass
13691369

13701370
@property

0 commit comments

Comments
 (0)