diff --git a/scripts/build_aws_lambda_layer.py b/scripts/build_aws_lambda_layer.py index a1078f4e19..fce67080de 100644 --- a/scripts/build_aws_lambda_layer.py +++ b/scripts/build_aws_lambda_layer.py @@ -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 = ( @@ -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( @@ -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 @@ -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", diff --git a/scripts/init_serverless_sdk.py b/scripts/init_serverless_sdk.py index 9b4412c420..49f8834e1b 100644 --- a/scripts/init_serverless_sdk.py +++ b/scripts/init_serverless_sdk.py @@ -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" diff --git a/sentry_sdk/integrations/mcp.py b/sentry_sdk/integrations/mcp.py index 6a7edbb7ba..47fda272b7 100644 --- a/sentry_sdk/integrations/mcp.py +++ b/sentry_sdk/integrations/mcp.py @@ -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. diff --git a/tests/conftest.py b/tests/conftest.py index 9c2115f1d8..dea36f8bda 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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() diff --git a/tests/integrations/django/test_middleware.py b/tests/integrations/django/test_middleware.py index 2a8d94f623..9c4c1ddfd1 100644 --- a/tests/integrations/django/test_middleware.py +++ b/tests/integrations/django/test_middleware.py @@ -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. """ diff --git a/tests/integrations/huggingface_hub/test_huggingface_hub.py b/tests/integrations/huggingface_hub/test_huggingface_hub.py index f0af26395a..851c1f717a 100644 --- a/tests/integrations/huggingface_hub/test_huggingface_hub.py +++ b/tests/integrations/huggingface_hub/test_huggingface_hub.py @@ -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, @@ -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, @@ -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, @@ -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, @@ -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() @@ -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() @@ -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, @@ -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, diff --git a/tests/integrations/sanic/test_sanic.py b/tests/integrations/sanic/test_sanic.py index 0419127239..ff1c5efa26 100644 --- a/tests/integrations/sanic/test_sanic.py +++ b/tests/integrations/sanic/test_sanic.py @@ -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 """ @@ -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)], diff --git a/tests/profiler/test_transaction_profiler.py b/tests/profiler/test_transaction_profiler.py index 142fd7d78c..2ba11bfcea 100644 --- a/tests/profiler/test_transaction_profiler.py +++ b/tests/profiler/test_transaction_profiler.py @@ -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 diff --git a/tests/test_basics.py b/tests/test_basics.py index b0b577b796..da836462d8 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -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. """ diff --git a/tests/test_client.py b/tests/test_client.py index 35edfdb5b7..043c7c6ae5 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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 @@ -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() diff --git a/tests/test_logs.py b/tests/test_logs.py index 19b35006e8..7bdf80365f 100644 --- a/tests/test_logs.py +++ b/tests/test_logs.py @@ -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": @@ -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" ], @@ -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 diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 450538d763..ee37ee467c 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -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"), @@ -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 diff --git a/tests/test_tracing_utils.py b/tests/test_tracing_utils.py index 9dd0771674..8960e04321 100644 --- a/tests/test_tracing_utils.py +++ b/tests/test_tracing_utils.py @@ -10,8 +10,7 @@ from tests.conftest import TestTransportWithOptions -def id_function(val): - # type: (object) -> str +def id_function(val: object) -> str: if isinstance(val, ShouldBeIncludedTestCase): return val.id @@ -93,8 +92,9 @@ class ShouldBeIncludedTestCase: ], ids=id_function, ) -def test_should_be_included(test_case, expected): - # type: (ShouldBeIncludedTestCase, bool) -> None +def test_should_be_included( + test_case: "ShouldBeIncludedTestCase", expected: bool +) -> None: """Checking logic, see: https://github.com/getsentry/sentry-python/issues/3312""" kwargs = asdict(test_case) kwargs.pop("id") diff --git a/tests/test_transport.py b/tests/test_transport.py index fc64a1e53c..b5b88e0e2c 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -63,8 +63,7 @@ def inner(**kwargs): return inner -def mock_transaction_envelope(span_count): - # type: (int) -> Envelope +def mock_transaction_envelope(span_count: int) -> "Envelope": event = defaultdict( mock.MagicMock, type="transaction", diff --git a/tests/test_utils.py b/tests/test_utils.py index e1c6786e1b..d703e62f3a 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -53,8 +53,7 @@ class TestIntegration(Integration): gevent = None -def _normalize_distribution_name(name): - # type: (str) -> str +def _normalize_distribution_name(name: str) -> str: """Normalize distribution name according to PEP-0503. See: