Skip to content

Commit 0e80b58

Browse files
committed
Migrate more type comments to annotations
1 parent 146f101 commit 0e80b58

File tree

17 files changed

+56
-84
lines changed

17 files changed

+56
-84
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
@@ -84,8 +80,7 @@ def create_init_serverless_sdk_package(self):
8480
"scripts/init_serverless_sdk.py", f"{serverless_sdk_path}/__init__.py"
8581
)
8682

87-
def zip(self):
88-
# type: (...) -> None
83+
def zip(self) -> None:
8984
subprocess.run(
9085
[
9186
"zip",

scripts/init_serverless_sdk.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@
99
import os
1010
import sys
1111
import re
12+
from typing import Any
1213

1314
import sentry_sdk
1415
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
1516

16-
from typing import TYPE_CHECKING
17-
18-
if TYPE_CHECKING:
19-
from typing import Any
20-
2117

2218
# Configure Sentry SDK
2319
sentry_sdk.init(
@@ -70,8 +66,7 @@ def get_lambda_handler(self):
7066
return getattr(self.lambda_function_module, self.handler_name)
7167

7268

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

sentry_sdk/api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,5 @@ def end_session() -> None:
339339

340340

341341
@scopemethod
342-
def set_transaction_name(name, source=None):
343-
# type: (str, Optional[str]) -> None
342+
def set_transaction_name(name: str, source: Optional[str] = None) -> None:
344343
return get_current_scope().set_transaction_name(name, source)

sentry_sdk/integrations/django/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,7 @@ def _set_db_data(span: Span, cursor_or_db: Any) -> None:
712712
span.set_attribute(SPANDATA.SERVER_SOCKET_ADDRESS, server_socket_address)
713713

714714

715-
def add_template_context_repr_sequence():
716-
# type: () -> None
715+
def add_template_context_repr_sequence() -> None:
717716
try:
718717
from django.template.context import BaseContext
719718

sentry_sdk/serializer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ def add_global_repr_processor(processor: ReprProcessor) -> None:
5353
global_repr_processors.append(processor)
5454

5555

56-
sequence_types = [Sequence, Set] # type: List[type]
56+
sequence_types: list[type] = [Sequence, Set]
5757

5858

59-
def add_repr_sequence_type(ty):
60-
# type: (type) -> None
59+
def add_repr_sequence_type(ty: type) -> None:
6160
sequence_types.append(ty)
6261

6362

sentry_sdk/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,12 +1875,12 @@ def set_thread_info_from_span(
18751875
data[SPANDATA.THREAD_NAME] = span.get_attribute(SPANDATA.THREAD_NAME)
18761876

18771877

1878-
def safe_serialize(data):
1879-
# type: (Any) -> str
1878+
def safe_serialize(data: Any) -> str:
18801879
"""Safely serialize to a readable string."""
18811880

1882-
def serialize_item(item):
1883-
# type: (Any) -> Union[str, dict[Any, Any], list[Any], tuple[Any, ...]]
1881+
def serialize_item(
1882+
item: Any,
1883+
) -> Union[str, dict[Any, Any], list[Any], tuple[Any, ...]]:
18841884
if callable(item):
18851885
try:
18861886
module = getattr(item, "__module__", None)

tests/integrations/chalice/test_chalice.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
from pytest_chalice.handlers import RequestHandler
1111

1212

13-
def _generate_lambda_context(self):
13+
def _generate_lambda_context(self) -> LambdaContext:
1414
# Monkeypatch of the function _generate_lambda_context
1515
# from the class LocalGateway
1616
# for mock the timeout
17-
# type: () -> LambdaContext
1817
if self._config.lambda_timeout is None:
1918
timeout = 10 * 1000
2019
else:

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/langchain/test_langchain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def get_word_length(word: str) -> int:
3434
return len(word)
3535

3636

37-
global stream_result_mock # type: Mock
38-
global llm_type # type: str
37+
stream_result_mock: Mock
38+
llm_type: str
3939

4040

4141
class MockOpenAI(ChatOpenAI):

tests/integrations/sanic/test_sanic.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os
44
import random
55
import sys
6+
from typing import Any, Iterable, Optional
7+
from collections.abc import Container
68
from unittest.mock import Mock
79

810
import pytest
@@ -26,11 +28,6 @@
2628
except ImportError:
2729
ReusableClient = None
2830

29-
from typing import TYPE_CHECKING
30-
31-
if TYPE_CHECKING:
32-
from collections.abc import Iterable, Container
33-
from typing import Any, Optional
3431

3532
SANIC_VERSION = tuple(map(int, SANIC_VERSION_RAW.split(".")))
3633
PERFORMANCE_SUPPORTED = SANIC_VERSION >= (21, 9)
@@ -341,14 +338,13 @@ class TransactionTestConfig:
341338

342339
def __init__(
343340
self,
344-
integration_args,
345-
url,
346-
expected_status,
347-
expected_transaction_name,
348-
expected_source=None,
349-
has_transaction_event=True,
350-
):
351-
# type: (Iterable[Optional[Container[int]]], str, int, Optional[str], Optional[str], bool) -> None
341+
integration_args: Iterable[Optional[Container[int]]],
342+
url: str,
343+
expected_status: int,
344+
expected_transaction_name: Optional[str],
345+
expected_source: Optional[str] = None,
346+
has_transaction_event: bool = True,
347+
) -> None:
352348
"""
353349
expected_transaction_name of None indicates we expect to not receive a transaction
354350
"""
@@ -408,8 +404,9 @@ def __init__(
408404
),
409405
],
410406
)
411-
def test_transactions(test_config, sentry_init, app, capture_events):
412-
# type: (TransactionTestConfig, Any, Any, Any) -> None
407+
def test_transactions(
408+
test_config: TransactionTestConfig, sentry_init: Any, app: Any, capture_events: Any
409+
) -> None:
413410

414411
# Init the SanicIntegration with the desired arguments
415412
sentry_init(

0 commit comments

Comments
 (0)