Skip to content
Merged
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
19 changes: 7 additions & 12 deletions scripts/build_aws_lambda_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
class LayerBuilder:
def __init__(
self,
base_dir, # type: str
out_zip_filename=None, # type: Optional[str]
):
# type: (...) -> None
base_dir: str,
out_zip_filename: "Optional[str]"=None,
) -> None:
self.base_dir = base_dir
self.python_site_packages = os.path.join(self.base_dir, PYTHON_SITE_PACKAGES)
self.out_zip_filename = (
Expand All @@ -29,12 +28,10 @@ def __init__(
else out_zip_filename
)

def make_directories(self):
# type: (...) -> None
def make_directories(self) -> None:
os.makedirs(self.python_site_packages)

def install_python_packages(self):
# type: (...) -> None
def install_python_packages(self) -> None:
# Install requirements for Lambda Layer (these are more limited than the SDK requirements,
# because Lambda does not support the newest versions of some packages)
subprocess.check_call(
Expand Down Expand Up @@ -68,8 +65,7 @@ def install_python_packages(self):
check=True,
)

def create_init_serverless_sdk_package(self):
# type: (...) -> None
def create_init_serverless_sdk_package(self) -> None:
"""
Method that creates the init_serverless_sdk pkg in the
sentry-python-serverless zip
Expand All @@ -83,8 +79,7 @@ def create_init_serverless_sdk_package(self):
"scripts/init_serverless_sdk.py", f"{serverless_sdk_path}/__init__.py"
)

def zip(self):
# type: (...) -> None
def zip(self) -> None:
subprocess.run(
[
"zip",
Expand Down
3 changes: 1 addition & 2 deletions scripts/init_serverless_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def get_lambda_handler(self):
return getattr(self.lambda_function_module, self.handler_name)


def sentry_lambda_handler(event, context):
# type: (Any, Any) -> None
def sentry_lambda_handler(event: "Any", context: "Any") -> None:
"""
Handler function that invokes a lambda handler which path is defined in
environment variables as "SENTRY_INITIAL_HANDLER"
Expand Down
3 changes: 1 addition & 2 deletions sentry_sdk/integrations/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,7 @@ def patched_read_resource(
Server.read_resource = patched_read_resource


def _patch_fastmcp():
# type: () -> None
def _patch_fastmcp() -> None:
"""
Patches the standalone fastmcp package's FastMCP class.

Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,9 @@ def werkzeug_set_cookie(client, servername, key, value):


@contextmanager
def patch_start_tracing_child(fake_transaction_is_none=False):
# type: (bool) -> Iterator[Optional[mock.MagicMock]]
def patch_start_tracing_child(
fake_transaction_is_none: bool = False,
) -> "Iterator[Optional[mock.MagicMock]]":
if not fake_transaction_is_none:
fake_transaction = mock.MagicMock()
fake_start_child = mock.MagicMock()
Expand Down
3 changes: 1 addition & 2 deletions tests/integrations/django/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from sentry_sdk.integrations.django.middleware import _wrap_middleware


def _sync_capable_middleware_factory(sync_capable):
# type: (Optional[bool]) -> type
def _sync_capable_middleware_factory(sync_capable: "Optional[bool]") -> type:
"""Create a middleware class with a sync_capable attribute set to the value passed to the factory.
If the factory is called with None, the middleware class will not have a sync_capable attribute.
"""
Expand Down
88 changes: 41 additions & 47 deletions tests/integrations/huggingface_hub/test_huggingface_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,12 @@ def mock_hf_chat_completion_api_streaming_tools(httpx_mock):
@pytest.mark.parametrize("send_default_pii", [True, False])
@pytest.mark.parametrize("include_prompts", [True, False])
def test_text_generation(
sentry_init,
capture_events,
send_default_pii,
include_prompts,
mock_hf_text_generation_api,
):
# type: (Any, Any, Any, Any, Any) -> None
sentry_init: "Any",
capture_events: "Any",
send_default_pii: "Any",
include_prompts: "Any",
mock_hf_text_generation_api: "Any",
) -> None:
sentry_init(
traces_sample_rate=1.0,
send_default_pii=send_default_pii,
Expand Down Expand Up @@ -541,13 +540,12 @@ def test_text_generation(
@pytest.mark.parametrize("send_default_pii", [True, False])
@pytest.mark.parametrize("include_prompts", [True, False])
def test_text_generation_streaming(
sentry_init,
capture_events,
send_default_pii,
include_prompts,
mock_hf_text_generation_api_streaming,
):
# type: (Any, Any, Any, Any, Any) -> None
sentry_init: "Any",
capture_events: "Any",
send_default_pii: "Any",
include_prompts: "Any",
mock_hf_text_generation_api_streaming: "Any",
) -> None:
sentry_init(
traces_sample_rate=1.0,
send_default_pii=send_default_pii,
Expand Down Expand Up @@ -611,13 +609,12 @@ def test_text_generation_streaming(
@pytest.mark.parametrize("send_default_pii", [True, False])
@pytest.mark.parametrize("include_prompts", [True, False])
def test_chat_completion(
sentry_init,
capture_events,
send_default_pii,
include_prompts,
mock_hf_chat_completion_api,
):
# type: (Any, Any, Any, Any, Any) -> None
sentry_init: "Any",
capture_events: "Any",
send_default_pii: "Any",
include_prompts: "Any",
mock_hf_chat_completion_api: "Any",
) -> None:
sentry_init(
traces_sample_rate=1.0,
send_default_pii=send_default_pii,
Expand Down Expand Up @@ -683,13 +680,12 @@ def test_chat_completion(
@pytest.mark.parametrize("send_default_pii", [True, False])
@pytest.mark.parametrize("include_prompts", [True, False])
def test_chat_completion_streaming(
sentry_init,
capture_events,
send_default_pii,
include_prompts,
mock_hf_chat_completion_api_streaming,
):
# type: (Any, Any, Any, Any, Any) -> None
sentry_init: "Any",
capture_events: "Any",
send_default_pii: "Any",
include_prompts: "Any",
mock_hf_chat_completion_api_streaming: "Any",
) -> None:
sentry_init(
traces_sample_rate=1.0,
send_default_pii=send_default_pii,
Expand Down Expand Up @@ -755,9 +751,8 @@ def test_chat_completion_streaming(

@pytest.mark.httpx_mock(assert_all_requests_were_expected=False)
def test_chat_completion_api_error(
sentry_init, capture_events, mock_hf_api_with_errors
):
# type: (Any, Any, Any) -> None
sentry_init: "Any", capture_events: "Any", mock_hf_api_with_errors: "Any"
) -> None:
sentry_init(traces_sample_rate=1.0)
events = capture_events()

Expand Down Expand Up @@ -809,8 +804,9 @@ def test_chat_completion_api_error(


@pytest.mark.httpx_mock(assert_all_requests_were_expected=False)
def test_span_status_error(sentry_init, capture_events, mock_hf_api_with_errors):
# type: (Any, Any, Any) -> None
def test_span_status_error(
sentry_init: "Any", capture_events: "Any", mock_hf_api_with_errors: "Any"
) -> None:
sentry_init(traces_sample_rate=1.0)
events = capture_events()

Expand Down Expand Up @@ -846,13 +842,12 @@ def test_span_status_error(sentry_init, capture_events, mock_hf_api_with_errors)
@pytest.mark.parametrize("send_default_pii", [True, False])
@pytest.mark.parametrize("include_prompts", [True, False])
def test_chat_completion_with_tools(
sentry_init,
capture_events,
send_default_pii,
include_prompts,
mock_hf_chat_completion_api_tools,
):
# type: (Any, Any, Any, Any, Any) -> None
sentry_init: "Any",
capture_events: "Any",
send_default_pii: "Any",
include_prompts: "Any",
mock_hf_chat_completion_api_tools: "Any",
) -> None:
sentry_init(
traces_sample_rate=1.0,
send_default_pii=send_default_pii,
Expand Down Expand Up @@ -935,13 +930,12 @@ def test_chat_completion_with_tools(
@pytest.mark.parametrize("send_default_pii", [True, False])
@pytest.mark.parametrize("include_prompts", [True, False])
def test_chat_completion_streaming_with_tools(
sentry_init,
capture_events,
send_default_pii,
include_prompts,
mock_hf_chat_completion_api_streaming_tools,
):
# type: (Any, Any, Any, Any, Any) -> None
sentry_init: "Any",
capture_events: "Any",
send_default_pii: "Any",
include_prompts: "Any",
mock_hf_chat_completion_api_streaming_tools: "Any",
) -> None:
sentry_init(
traces_sample_rate=1.0,
send_default_pii=send_default_pii,
Expand Down
22 changes: 12 additions & 10 deletions tests/integrations/sanic/test_sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,12 @@ class TransactionTestConfig:

def __init__(
self,
integration_args,
url,
expected_status,
expected_transaction_name,
expected_source=None,
):
# type: (Iterable[Optional[Container[int]]], str, int, Optional[str], Optional[str]) -> None
integration_args: "Iterable[Optional[Container[int]]]",
url: str,
expected_status: int,
expected_transaction_name: "Optional[str]",
expected_source: "Optional[str]" = None,
) -> None:
"""
expected_transaction_name of None indicates we expect to not receive a transaction
"""
Expand Down Expand Up @@ -404,9 +403,12 @@ def __init__(
),
],
)
def test_transactions(test_config, sentry_init, app, capture_events):
# type: (TransactionTestConfig, Any, Any, Any) -> None

def test_transactions(
test_config: "TransactionTestConfig",
sentry_init: "Any",
app: "Any",
capture_events: "Any",
) -> None:
# Init the SanicIntegration with the desired arguments
sentry_init(
integrations=[SanicIntegration(*test_config.integration_args)],
Expand Down
9 changes: 3 additions & 6 deletions tests/profiler/test_transaction_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,16 +664,13 @@ def test_max_profile_duration_reached(scheduler_class):


class NoopScheduler(Scheduler):
def setup(self):
# type: () -> None
def setup(self) -> None:
pass

def teardown(self):
# type: () -> None
def teardown(self) -> None:
pass

def ensure_running(self):
# type: () -> None
def ensure_running(self) -> None:
pass


Expand Down
4 changes: 2 additions & 2 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class NoOpIntegration(Integration):
identifier = "noop"

@staticmethod
def setup_once(): # type: () -> None
def setup_once() -> None:
pass

def __eq__(self, __value): # type: (object) -> bool
def __eq__(self, __value: object) -> bool:
"""
All instances of NoOpIntegration should be considered equal to each other.
"""
Expand Down
17 changes: 7 additions & 10 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,12 +1214,11 @@ def test_spotlight_option(
class IssuesSamplerTestConfig:
def __init__(
self,
expected_events,
sampler_function=None,
sample_rate=None,
exception_to_raise=Exception,
):
# type: (int, Optional[Callable[[Event], Union[float, bool]]], Optional[float], type[Exception]) -> None
expected_events: int,
sampler_function: "Optional[Callable[[Event], Union[float, bool]]]" = None,
sample_rate: "Optional[float]" = None,
exception_to_raise: "type[Exception]" = Exception,
) -> None:
self.sampler_function_mock = (
None
if sampler_function is None
Expand All @@ -1229,14 +1228,12 @@ def __init__(
self.sample_rate = sample_rate
self.exception_to_raise = exception_to_raise

def init_sdk(self, sentry_init):
# type: (Callable[[*Any], None]) -> None
def init_sdk(self, sentry_init: "Callable[[*Any], None]") -> None:
sentry_init(
error_sampler=self.sampler_function_mock, sample_rate=self.sample_rate
)

def raise_exception(self):
# type: () -> None
def raise_exception(self) -> None:
raise self.exception_to_raise()


Expand Down
10 changes: 4 additions & 6 deletions tests/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
)


def otel_attributes_to_dict(otel_attrs):
# type: (Mapping[str, Any]) -> Mapping[str, Any]
def otel_attributes_to_dict(otel_attrs: "Mapping[str, Any]") -> "Mapping[str, Any]":
def _convert_attr(attr):
# type: (Mapping[str, Union[str, float, bool]]) -> Any
if attr["type"] == "boolean":
Expand All @@ -39,12 +38,12 @@ def _convert_attr(attr):


def envelopes_to_logs(envelopes: List[Envelope]) -> List[Log]:
res = [] # type: List[Log]
res: "List[Log]" = []
for envelope in envelopes:
for item in envelope.items:
if item.type == "log":
for log_json in item.payload.json["items"]:
log = {
log: "Log" = {
"severity_text": log_json["attributes"]["sentry.severity_text"][
"value"
],
Expand All @@ -56,8 +55,7 @@ def envelopes_to_logs(envelopes: List[Envelope]) -> List[Log]:
"time_unix_nano": int(float(log_json["timestamp"]) * 1e9),
"trace_id": log_json["trace_id"],
"span_id": log_json["span_id"],
} # type: Log

}
res.append(log)
return res

Expand Down
7 changes: 3 additions & 4 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
from sentry_sdk.consts import SPANDATA, VERSION


def envelopes_to_metrics(envelopes):
# type: (List[Envelope]) -> List[Metric]
def envelopes_to_metrics(envelopes: "List[Envelope]") -> "List[Metric]":
res = [] # type: List[Metric]
for envelope in envelopes:
for item in envelope.items:
if item.type == "trace_metric":
for metric_json in item.payload.json["items"]:
metric = {
metric: "Metric" = {
"timestamp": metric_json["timestamp"],
"trace_id": metric_json["trace_id"],
"span_id": metric_json.get("span_id"),
Expand All @@ -29,7 +28,7 @@ def envelopes_to_metrics(envelopes):
k: v["value"]
for (k, v) in metric_json["attributes"].items()
},
} # type: Metric
}
res.append(metric)
return res

Expand Down
Loading
Loading