Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,46 @@ disallow_subclassing_any = false
warn_unused_ignores = false
disable_error_code = ["import-not-found", "import-untyped", "annotation-unchecked"]

# Core tests (no third-party dependencies) also have the bodies of untyped
# functions checked.
[[tool.mypy.overrides]]
module = [
"tests.test_ai_monitoring",
"tests.test_api",
"tests.test_attributes",
"tests.test_basics",
"tests.test_client",
"tests.test_conftest",
"tests.test_crons",
"tests.test_data_collection",
"tests.test_dsc",
"tests.test_envelope",
"tests.test_exceptiongroup",
"tests.test_feature_flags",
"tests.test_full_stack_frames",
"tests.test_gevent",
"tests.test_import",
"tests.test_logs",
"tests.test_lru_cache",
"tests.test_metrics",
"tests.test_monitor",
"tests.test_propagationcontext",
"tests.test_scope",
"tests.test_serializer",
"tests.test_sessions",
"tests.test_shadowed_module",
"tests.test_spotlight",
"tests.test_tracing_utils",
"tests.test_transport",
"tests.test_types",
"tests.test_utils",
"tests.profiler.*",
"tests.tracing.*",
"tests.utils.*",
]
check_untyped_defs = true
warn_unused_ignores = true

#
# Tool: Ruff (linting and formatting)
#
Expand Down
6 changes: 5 additions & 1 deletion tests/profiler/test_continuous_profiler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import threading
import time
from collections import defaultdict
from typing import TYPE_CHECKING
from unittest import mock

import pytest
Expand All @@ -16,6 +17,9 @@
)
from tests.conftest import ApproxDict

if TYPE_CHECKING:
from sentry_sdk._types import SDKInfo

try:
import gevent
except ImportError:
Expand Down Expand Up @@ -59,7 +63,7 @@ def wait_for_profiler_to_stop(envelopes, timeout=1.0):
), "profiler should have flushed a profile chunk"


mock_sdk_info = {
mock_sdk_info: "SDKInfo" = {
"name": "sentry.python",
"version": VERSION,
"packages": [{"name": "pypi:sentry-sdk", "version": VERSION}],
Expand Down
34 changes: 17 additions & 17 deletions tests/test_ai_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_empty_mime_type_returns_image(self):

def test_none_mime_type_returns_image(self):
"""Test that None-like values default to 'image'"""
assert get_modality_from_mime_type(None) == "image"
assert get_modality_from_mime_type(None) == "image" # type: ignore[arg-type]

def test_unknown_mime_type_returns_image(self):
"""Test that unknown MIME types default to 'image'"""
Expand Down Expand Up @@ -227,9 +227,9 @@ def test_google_format_returns_none(self):

def test_non_dict_returns_none(self):
"""Test that non-dict input returns None"""
assert transform_openai_content_part("string") is None
assert transform_openai_content_part(123) is None
assert transform_openai_content_part(None) is None
assert transform_openai_content_part("string") is None # type: ignore[arg-type]
assert transform_openai_content_part(123) is None # type: ignore[arg-type]
assert transform_openai_content_part(None) is None # type: ignore[arg-type]


class TestTransformAnthropicContentPart:
Expand Down Expand Up @@ -363,9 +363,9 @@ def test_google_format_returns_none(self):

def test_non_dict_returns_none(self):
"""Test that non-dict input returns None"""
assert transform_anthropic_content_part("string") is None
assert transform_anthropic_content_part(123) is None
assert transform_anthropic_content_part(None) is None
assert transform_anthropic_content_part("string") is None # type: ignore[arg-type]
assert transform_anthropic_content_part(123) is None # type: ignore[arg-type]
assert transform_anthropic_content_part(None) is None # type: ignore[arg-type]


class TestTransformGoogleContentPart:
Expand Down Expand Up @@ -450,9 +450,9 @@ def test_anthropic_format_returns_none(self):

def test_non_dict_returns_none(self):
"""Test that non-dict input returns None"""
assert transform_google_content_part("string") is None
assert transform_google_content_part(123) is None
assert transform_google_content_part(None) is None
assert transform_google_content_part("string") is None # type: ignore[arg-type]
assert transform_google_content_part(123) is None # type: ignore[arg-type]
assert transform_google_content_part(None) is None # type: ignore[arg-type]


class TestTransformGenericContentPart:
Expand Down Expand Up @@ -551,9 +551,9 @@ def test_google_format_returns_none(self):

def test_non_dict_returns_none(self):
"""Test that non-dict input returns None"""
assert transform_generic_content_part("string") is None
assert transform_generic_content_part(123) is None
assert transform_generic_content_part(None) is None
assert transform_generic_content_part("string") is None # type: ignore[arg-type]
assert transform_generic_content_part(123) is None # type: ignore[arg-type]
assert transform_generic_content_part(None) is None # type: ignore[arg-type]

def test_missing_data_key_returns_none(self):
"""Test that missing data key (base64/url/file_id) returns None"""
Expand Down Expand Up @@ -846,10 +846,10 @@ def test_text_block_returns_none(self):

def test_non_dict_returns_none(self):
"""Test that non-dict input returns None"""
assert transform_content_part("string") is None
assert transform_content_part(123) is None
assert transform_content_part(None) is None
assert transform_content_part([1, 2, 3]) is None
assert transform_content_part("string") is None # type: ignore[arg-type]
assert transform_content_part(123) is None # type: ignore[arg-type]
assert transform_content_part(None) is None # type: ignore[arg-type]
assert transform_content_part([1, 2, 3]) is None # type: ignore[arg-type]

def test_empty_dict_returns_none(self):
"""Test that empty dict returns None"""
Expand Down
11 changes: 9 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def test_traceparent_with_tracing_disabled(sentry_init):
sentry_init()

propagation_context = get_isolation_scope()._propagation_context
assert propagation_context is not None
expected_traceparent = "%s-%s" % (
propagation_context.trace_id,
propagation_context.span_id,
Expand All @@ -83,6 +84,7 @@ def test_traceparent_with_tracing_disabled(sentry_init):
def test_baggage_with_tracing_disabled(sentry_init):
sentry_init(release="1.0.0", environment="dev")
propagation_context = get_isolation_scope()._propagation_context
assert propagation_context is not None
expected_baggage = (
"sentry-trace_id={},sentry-environment=dev,sentry-release=1.0.0".format(
propagation_context.trace_id
Expand All @@ -101,7 +103,9 @@ def test_baggage_with_tracing_enabled(sentry_init):
expected_baggage_re = r"^sentry-trace_id={},sentry-sample_rand=0\.\d{{6}},sentry-environment=dev,sentry-release=1\.0\.0,sentry-transaction=segment,sentry-sample_rate=1\.0,sentry-sampled={}$".format(
segment.trace_id, "true" if segment.sampled else "false"
)
assert re.match(expected_baggage_re, get_baggage())
baggage = get_baggage()
assert baggage is not None
assert re.match(expected_baggage_re, baggage)


def test_baggage_with_dsn(sentry_init):
Expand All @@ -116,7 +120,9 @@ def test_baggage_with_dsn(sentry_init):
expected_baggage_re = r"^sentry-trace_id={},sentry-sample_rand=0\.\d{{6}},sentry-environment=dev,sentry-release=2\.0\.0,sentry-public_key=97333d956c9e40989a0139756c121c34,sentry-transaction=segment,sentry-sample_rate=1\.0,sentry-sampled={}$".format(
segment.trace_id, "true" if segment.sampled else "false"
)
assert re.match(expected_baggage_re, get_baggage())
baggage = get_baggage()
assert baggage is not None
assert re.match(expected_baggage_re, baggage)


def test_continue_trace(sentry_init):
Expand All @@ -135,6 +141,7 @@ def test_continue_trace(sentry_init):
assert segment.name == "some name"

propagation_context = get_isolation_scope()._propagation_context
assert propagation_context is not None
assert propagation_context.trace_id == segment.trace_id == trace_id
assert propagation_context.parent_span_id == parent_span_id
assert propagation_context.parent_sampled == parent_sampled
Expand Down
4 changes: 2 additions & 2 deletions tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ class Cat:
dictionary = {"color": "tortoiseshell"}

with sentry_sdk.new_scope() as scope:
scope.set_attribute("instance", instance)
scope.set_attribute("dictionary", dictionary)
scope.set_attribute("instance", instance) # type: ignore[arg-type]
scope.set_attribute("dictionary", dictionary) # type: ignore[arg-type]

# Scope attrs are stored preserialized
assert isinstance(scope._attributes["instance"], str)
Expand Down
6 changes: 4 additions & 2 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time
import weakref
from collections import Counter
from typing import Optional

import pytest

Expand Down Expand Up @@ -663,7 +664,7 @@ def test_dedupe_does_not_retain_builtin_exceptions(sentry_init):
class Payload:
pass

payload_ref = None
payload_ref: "Optional[weakref.ReferenceType[Payload]]" = None

def fail():
nonlocal payload_ref
Expand All @@ -680,6 +681,7 @@ def capture():
capture()

gc.collect()
assert payload_ref is not None
assert payload_ref() is None


Expand Down Expand Up @@ -943,7 +945,7 @@ def test_functions_to_trace_with_class(sentry_init, capture_items):
assert child_spans[1]["name"] == "tests.test_basics.WorldGreeter.greet"

finally:
WorldGreeter.greet = original_function
WorldGreeter.greet = original_function # type: ignore[method-assign]


def test_multiple_setup_integrations_calls():
Expand Down
Loading
Loading