Skip to content

Commit e275c9e

Browse files
authored
Convert all remaining type annotations to PEP-526 format (#5239)
1 parent a29b421 commit e275c9e

File tree

15 files changed

+91
-113
lines changed

15 files changed

+91
-113
lines changed

scripts/build_aws_lambda_layer.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
class LayerBuilder:
1818
def __init__(
1919
self,
20-
base_dir, # type: str
21-
out_zip_filename=None, # type: Optional[str]
22-
):
23-
# type: (...) -> None
20+
base_dir: str,
21+
out_zip_filename: "Optional[str]"=None,
22+
) -> None:
2423
self.base_dir = base_dir
2524
self.python_site_packages = os.path.join(self.base_dir, PYTHON_SITE_PACKAGES)
2625
self.out_zip_filename = (
@@ -29,12 +28,10 @@ def __init__(
2928
else out_zip_filename
3029
)
3130

32-
def make_directories(self):
33-
# type: (...) -> None
31+
def make_directories(self) -> None:
3432
os.makedirs(self.python_site_packages)
3533

36-
def install_python_packages(self):
37-
# type: (...) -> None
34+
def install_python_packages(self) -> None:
3835
# Install requirements for Lambda Layer (these are more limited than the SDK requirements,
3936
# because Lambda does not support the newest versions of some packages)
4037
subprocess.check_call(
@@ -68,8 +65,7 @@ def install_python_packages(self):
6865
check=True,
6966
)
7067

71-
def create_init_serverless_sdk_package(self):
72-
# type: (...) -> None
68+
def create_init_serverless_sdk_package(self) -> None:
7369
"""
7470
Method that creates the init_serverless_sdk pkg in the
7571
sentry-python-serverless zip
@@ -83,8 +79,7 @@ def create_init_serverless_sdk_package(self):
8379
"scripts/init_serverless_sdk.py", f"{serverless_sdk_path}/__init__.py"
8480
)
8581

86-
def zip(self):
87-
# type: (...) -> None
82+
def zip(self) -> None:
8883
subprocess.run(
8984
[
9085
"zip",

scripts/init_serverless_sdk.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ def get_lambda_handler(self):
7070
return getattr(self.lambda_function_module, self.handler_name)
7171

7272

73-
def sentry_lambda_handler(event, context):
74-
# type: (Any, Any) -> None
73+
def sentry_lambda_handler(event: "Any", context: "Any") -> None:
7574
"""
7675
Handler function that invokes a lambda handler which path is defined in
7776
environment variables as "SENTRY_INITIAL_HANDLER"

sentry_sdk/integrations/mcp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,7 @@ def patched_read_resource(
618618
Server.read_resource = patched_read_resource
619619

620620

621-
def _patch_fastmcp():
622-
# type: () -> None
621+
def _patch_fastmcp() -> None:
623622
"""
624623
Patches the standalone fastmcp package's FastMCP class.
625624

tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,9 @@ def werkzeug_set_cookie(client, servername, key, value):
644644

645645

646646
@contextmanager
647-
def patch_start_tracing_child(fake_transaction_is_none=False):
648-
# type: (bool) -> Iterator[Optional[mock.MagicMock]]
647+
def patch_start_tracing_child(
648+
fake_transaction_is_none: bool = False,
649+
) -> "Iterator[Optional[mock.MagicMock]]":
649650
if not fake_transaction_is_none:
650651
fake_transaction = mock.MagicMock()
651652
fake_start_child = mock.MagicMock()

tests/integrations/django/test_middleware.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
from sentry_sdk.integrations.django.middleware import _wrap_middleware
66

77

8-
def _sync_capable_middleware_factory(sync_capable):
9-
# type: (Optional[bool]) -> type
8+
def _sync_capable_middleware_factory(sync_capable: "Optional[bool]") -> type:
109
"""Create a middleware class with a sync_capable attribute set to the value passed to the factory.
1110
If the factory is called with None, the middleware class will not have a sync_capable attribute.
1211
"""

tests/integrations/huggingface_hub/test_huggingface_hub.py

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,12 @@ def mock_hf_chat_completion_api_streaming_tools(httpx_mock):
472472
@pytest.mark.parametrize("send_default_pii", [True, False])
473473
@pytest.mark.parametrize("include_prompts", [True, False])
474474
def test_text_generation(
475-
sentry_init,
476-
capture_events,
477-
send_default_pii,
478-
include_prompts,
479-
mock_hf_text_generation_api,
480-
):
481-
# type: (Any, Any, Any, Any, Any) -> None
475+
sentry_init: "Any",
476+
capture_events: "Any",
477+
send_default_pii: "Any",
478+
include_prompts: "Any",
479+
mock_hf_text_generation_api: "Any",
480+
) -> None:
482481
sentry_init(
483482
traces_sample_rate=1.0,
484483
send_default_pii=send_default_pii,
@@ -541,13 +540,12 @@ def test_text_generation(
541540
@pytest.mark.parametrize("send_default_pii", [True, False])
542541
@pytest.mark.parametrize("include_prompts", [True, False])
543542
def test_text_generation_streaming(
544-
sentry_init,
545-
capture_events,
546-
send_default_pii,
547-
include_prompts,
548-
mock_hf_text_generation_api_streaming,
549-
):
550-
# type: (Any, Any, Any, Any, Any) -> None
543+
sentry_init: "Any",
544+
capture_events: "Any",
545+
send_default_pii: "Any",
546+
include_prompts: "Any",
547+
mock_hf_text_generation_api_streaming: "Any",
548+
) -> None:
551549
sentry_init(
552550
traces_sample_rate=1.0,
553551
send_default_pii=send_default_pii,
@@ -611,13 +609,12 @@ def test_text_generation_streaming(
611609
@pytest.mark.parametrize("send_default_pii", [True, False])
612610
@pytest.mark.parametrize("include_prompts", [True, False])
613611
def test_chat_completion(
614-
sentry_init,
615-
capture_events,
616-
send_default_pii,
617-
include_prompts,
618-
mock_hf_chat_completion_api,
619-
):
620-
# type: (Any, Any, Any, Any, Any) -> None
612+
sentry_init: "Any",
613+
capture_events: "Any",
614+
send_default_pii: "Any",
615+
include_prompts: "Any",
616+
mock_hf_chat_completion_api: "Any",
617+
) -> None:
621618
sentry_init(
622619
traces_sample_rate=1.0,
623620
send_default_pii=send_default_pii,
@@ -683,13 +680,12 @@ def test_chat_completion(
683680
@pytest.mark.parametrize("send_default_pii", [True, False])
684681
@pytest.mark.parametrize("include_prompts", [True, False])
685682
def test_chat_completion_streaming(
686-
sentry_init,
687-
capture_events,
688-
send_default_pii,
689-
include_prompts,
690-
mock_hf_chat_completion_api_streaming,
691-
):
692-
# type: (Any, Any, Any, Any, Any) -> None
683+
sentry_init: "Any",
684+
capture_events: "Any",
685+
send_default_pii: "Any",
686+
include_prompts: "Any",
687+
mock_hf_chat_completion_api_streaming: "Any",
688+
) -> None:
693689
sentry_init(
694690
traces_sample_rate=1.0,
695691
send_default_pii=send_default_pii,
@@ -755,9 +751,8 @@ def test_chat_completion_streaming(
755751

756752
@pytest.mark.httpx_mock(assert_all_requests_were_expected=False)
757753
def test_chat_completion_api_error(
758-
sentry_init, capture_events, mock_hf_api_with_errors
759-
):
760-
# type: (Any, Any, Any) -> None
754+
sentry_init: "Any", capture_events: "Any", mock_hf_api_with_errors: "Any"
755+
) -> None:
761756
sentry_init(traces_sample_rate=1.0)
762757
events = capture_events()
763758

@@ -809,8 +804,9 @@ def test_chat_completion_api_error(
809804

810805

811806
@pytest.mark.httpx_mock(assert_all_requests_were_expected=False)
812-
def test_span_status_error(sentry_init, capture_events, mock_hf_api_with_errors):
813-
# type: (Any, Any, Any) -> None
807+
def test_span_status_error(
808+
sentry_init: "Any", capture_events: "Any", mock_hf_api_with_errors: "Any"
809+
) -> None:
814810
sentry_init(traces_sample_rate=1.0)
815811
events = capture_events()
816812

@@ -846,13 +842,12 @@ def test_span_status_error(sentry_init, capture_events, mock_hf_api_with_errors)
846842
@pytest.mark.parametrize("send_default_pii", [True, False])
847843
@pytest.mark.parametrize("include_prompts", [True, False])
848844
def test_chat_completion_with_tools(
849-
sentry_init,
850-
capture_events,
851-
send_default_pii,
852-
include_prompts,
853-
mock_hf_chat_completion_api_tools,
854-
):
855-
# type: (Any, Any, Any, Any, Any) -> None
845+
sentry_init: "Any",
846+
capture_events: "Any",
847+
send_default_pii: "Any",
848+
include_prompts: "Any",
849+
mock_hf_chat_completion_api_tools: "Any",
850+
) -> None:
856851
sentry_init(
857852
traces_sample_rate=1.0,
858853
send_default_pii=send_default_pii,
@@ -935,13 +930,12 @@ def test_chat_completion_with_tools(
935930
@pytest.mark.parametrize("send_default_pii", [True, False])
936931
@pytest.mark.parametrize("include_prompts", [True, False])
937932
def test_chat_completion_streaming_with_tools(
938-
sentry_init,
939-
capture_events,
940-
send_default_pii,
941-
include_prompts,
942-
mock_hf_chat_completion_api_streaming_tools,
943-
):
944-
# type: (Any, Any, Any, Any, Any) -> None
933+
sentry_init: "Any",
934+
capture_events: "Any",
935+
send_default_pii: "Any",
936+
include_prompts: "Any",
937+
mock_hf_chat_completion_api_streaming_tools: "Any",
938+
) -> None:
945939
sentry_init(
946940
traces_sample_rate=1.0,
947941
send_default_pii=send_default_pii,

tests/integrations/sanic/test_sanic.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,12 @@ class TransactionTestConfig:
341341

342342
def __init__(
343343
self,
344-
integration_args,
345-
url,
346-
expected_status,
347-
expected_transaction_name,
348-
expected_source=None,
349-
):
350-
# type: (Iterable[Optional[Container[int]]], str, int, Optional[str], Optional[str]) -> None
344+
integration_args: "Iterable[Optional[Container[int]]]",
345+
url: str,
346+
expected_status: int,
347+
expected_transaction_name: "Optional[str]",
348+
expected_source: "Optional[str]" = None,
349+
) -> None:
351350
"""
352351
expected_transaction_name of None indicates we expect to not receive a transaction
353352
"""
@@ -404,9 +403,12 @@ def __init__(
404403
),
405404
],
406405
)
407-
def test_transactions(test_config, sentry_init, app, capture_events):
408-
# type: (TransactionTestConfig, Any, Any, Any) -> None
409-
406+
def test_transactions(
407+
test_config: "TransactionTestConfig",
408+
sentry_init: "Any",
409+
app: "Any",
410+
capture_events: "Any",
411+
) -> None:
410412
# Init the SanicIntegration with the desired arguments
411413
sentry_init(
412414
integrations=[SanicIntegration(*test_config.integration_args)],

tests/profiler/test_transaction_profiler.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -664,16 +664,13 @@ def test_max_profile_duration_reached(scheduler_class):
664664

665665

666666
class NoopScheduler(Scheduler):
667-
def setup(self):
668-
# type: () -> None
667+
def setup(self) -> None:
669668
pass
670669

671-
def teardown(self):
672-
# type: () -> None
670+
def teardown(self) -> None:
673671
pass
674672

675-
def ensure_running(self):
676-
# type: () -> None
673+
def ensure_running(self) -> None:
677674
pass
678675

679676

tests/test_basics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ class NoOpIntegration(Integration):
4747
identifier = "noop"
4848

4949
@staticmethod
50-
def setup_once(): # type: () -> None
50+
def setup_once() -> None:
5151
pass
5252

53-
def __eq__(self, __value): # type: (object) -> bool
53+
def __eq__(self, __value: object) -> bool:
5454
"""
5555
All instances of NoOpIntegration should be considered equal to each other.
5656
"""

tests/test_client.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,12 +1214,11 @@ def test_spotlight_option(
12141214
class IssuesSamplerTestConfig:
12151215
def __init__(
12161216
self,
1217-
expected_events,
1218-
sampler_function=None,
1219-
sample_rate=None,
1220-
exception_to_raise=Exception,
1221-
):
1222-
# type: (int, Optional[Callable[[Event], Union[float, bool]]], Optional[float], type[Exception]) -> None
1217+
expected_events: int,
1218+
sampler_function: "Optional[Callable[[Event], Union[float, bool]]]" = None,
1219+
sample_rate: "Optional[float]" = None,
1220+
exception_to_raise: "type[Exception]" = Exception,
1221+
) -> None:
12231222
self.sampler_function_mock = (
12241223
None
12251224
if sampler_function is None
@@ -1229,14 +1228,12 @@ def __init__(
12291228
self.sample_rate = sample_rate
12301229
self.exception_to_raise = exception_to_raise
12311230

1232-
def init_sdk(self, sentry_init):
1233-
# type: (Callable[[*Any], None]) -> None
1231+
def init_sdk(self, sentry_init: "Callable[[*Any], None]") -> None:
12341232
sentry_init(
12351233
error_sampler=self.sampler_function_mock, sample_rate=self.sample_rate
12361234
)
12371235

1238-
def raise_exception(self):
1239-
# type: () -> None
1236+
def raise_exception(self) -> None:
12401237
raise self.exception_to_raise()
12411238

12421239

0 commit comments

Comments
 (0)