Skip to content

Commit 4b361c5

Browse files
ref(types): Replace custom TYPE_CHECKING with stdlib typing.TYPE_CHECKING (#3447)
--------- Co-authored-by: Ivana Kellyer <ivana.kellyer@sentry.io>
1 parent 306c34e commit 4b361c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+192
-142
lines changed

scripts/init_serverless_sdk.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
import re
1212

1313
import sentry_sdk
14-
from sentry_sdk._types import TYPE_CHECKING
1514
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
1615

16+
from typing import TYPE_CHECKING
17+
1718
if TYPE_CHECKING:
1819
from typing import Any
1920

sentry_sdk/_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22

3-
from sentry_sdk._types import TYPE_CHECKING
3+
from typing import TYPE_CHECKING
44

55
if TYPE_CHECKING:
66
from typing import Any

sentry_sdk/_queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
from collections import deque
7777
from time import time
7878

79-
from sentry_sdk._types import TYPE_CHECKING
79+
from typing import TYPE_CHECKING
8080

8181
if TYPE_CHECKING:
8282
from typing import Any

sentry_sdk/_types.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
try:
2-
from typing import TYPE_CHECKING
3-
except ImportError:
4-
TYPE_CHECKING = False
1+
from typing import TYPE_CHECKING
52

63

74
# Re-exported for compat, since code out there in the wild might use this variable.

sentry_sdk/_werkzeug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
SUCH DAMAGE.
3333
"""
3434

35-
from sentry_sdk._types import TYPE_CHECKING
35+
from typing import TYPE_CHECKING
3636

3737
if TYPE_CHECKING:
3838
from typing import Dict

sentry_sdk/ai/monitoring.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from sentry_sdk import start_span
66
from sentry_sdk.tracing import Span
77
from sentry_sdk.utils import ContextVar
8-
from sentry_sdk._types import TYPE_CHECKING
8+
9+
from typing import TYPE_CHECKING
910

1011
if TYPE_CHECKING:
1112
from typing import Optional, Callable, Any

sentry_sdk/ai/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from sentry_sdk._types import TYPE_CHECKING
1+
from typing import TYPE_CHECKING
22

33
if TYPE_CHECKING:
44
from typing import Any

sentry_sdk/api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
from sentry_sdk.tracing import NoOpSpan, Transaction, trace
1010
from sentry_sdk.crons import monitor
1111

12-
13-
from sentry_sdk._types import TYPE_CHECKING
12+
from typing import TYPE_CHECKING
1413

1514
if TYPE_CHECKING:
1615
from collections.abc import Mapping

sentry_sdk/attachments.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os
22
import mimetypes
33

4-
from sentry_sdk._types import TYPE_CHECKING
54
from sentry_sdk.envelope import Item, PayloadRef
65

6+
from typing import TYPE_CHECKING
7+
78
if TYPE_CHECKING:
89
from typing import Optional, Union, Callable
910

sentry_sdk/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from sentry_sdk.monitor import Monitor
4545
from sentry_sdk.spotlight import setup_spotlight
4646

47-
from sentry_sdk._types import TYPE_CHECKING
47+
from typing import TYPE_CHECKING
4848

4949
if TYPE_CHECKING:
5050
from typing import Any
@@ -881,7 +881,7 @@ def __exit__(self, exc_type, exc_value, tb):
881881
self.close()
882882

883883

884-
from sentry_sdk._types import TYPE_CHECKING
884+
from typing import TYPE_CHECKING
885885

886886
if TYPE_CHECKING:
887887
# Make mypy, PyCharm and other static analyzers think `get_options` is a

sentry_sdk/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import itertools
22

33
from enum import Enum
4-
from sentry_sdk._types import TYPE_CHECKING
4+
from typing import TYPE_CHECKING
55

66
# up top to prevent circular import due to integration import
77
DEFAULT_MAX_VALUE_LENGTH = 1024

sentry_sdk/crons/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import uuid
22

33
import sentry_sdk
4-
from sentry_sdk._types import TYPE_CHECKING
54

5+
from typing import TYPE_CHECKING
66

77
if TYPE_CHECKING:
88
from typing import Optional

sentry_sdk/crons/decorator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from functools import wraps
22
from inspect import iscoroutinefunction
33

4-
from sentry_sdk._types import TYPE_CHECKING
54
from sentry_sdk.crons import capture_checkin
65
from sentry_sdk.crons.consts import MonitorStatus
76
from sentry_sdk.utils import now
87

8+
from typing import TYPE_CHECKING
9+
910
if TYPE_CHECKING:
1011
from collections.abc import Awaitable, Callable
1112
from types import TracebackType

sentry_sdk/db/explain_plan/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from datetime import datetime, timedelta, timezone
2-
3-
from sentry_sdk.consts import TYPE_CHECKING
2+
from typing import TYPE_CHECKING
43

54
if TYPE_CHECKING:
65
from typing import Any

sentry_sdk/db/explain_plan/django.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from sentry_sdk.consts import TYPE_CHECKING
1+
from typing import TYPE_CHECKING
2+
23
from sentry_sdk.db.explain_plan import cache_statement, should_run_explain_plan
34

45
if TYPE_CHECKING:

sentry_sdk/db/explain_plan/sqlalchemy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from sentry_sdk.consts import TYPE_CHECKING
1+
from typing import TYPE_CHECKING
2+
23
from sentry_sdk.db.explain_plan import cache_statement, should_run_explain_plan
34
from sentry_sdk.integrations import DidNotEnable
45

sentry_sdk/envelope.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import json
33
import mimetypes
44

5-
from sentry_sdk._types import TYPE_CHECKING
65
from sentry_sdk.session import Session
76
from sentry_sdk.utils import json_dumps, capture_internal_exceptions
87

8+
from typing import TYPE_CHECKING
9+
910
if TYPE_CHECKING:
1011
from typing import Any
1112
from typing import Optional

sentry_sdk/hub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
ContextVar,
2323
)
2424

25-
from sentry_sdk._types import TYPE_CHECKING
25+
from typing import TYPE_CHECKING
2626

2727
if TYPE_CHECKING:
2828
from typing import Any

sentry_sdk/integrations/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from abc import ABC, abstractmethod
22
from threading import Lock
33

4-
from sentry_sdk._types import TYPE_CHECKING
54
from sentry_sdk.utils import logger
65

6+
from typing import TYPE_CHECKING
77

88
if TYPE_CHECKING:
99
from collections.abc import Sequence

sentry_sdk/integrations/_asgi_common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from sentry_sdk.scope import should_send_default_pii
44
from sentry_sdk.integrations._wsgi_common import _filter_headers
5-
from sentry_sdk._types import TYPE_CHECKING
5+
6+
from typing import TYPE_CHECKING
67

78
if TYPE_CHECKING:
89
from typing import Any

sentry_sdk/integrations/_wsgi_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import sentry_sdk
55
from sentry_sdk.scope import should_send_default_pii
66
from sentry_sdk.utils import AnnotatedValue, logger
7-
from sentry_sdk._types import TYPE_CHECKING
87

98
try:
109
from django.http.request import RawPostDataException
1110
except ImportError:
1211
RawPostDataException = None
1312

13+
from typing import TYPE_CHECKING
1414

1515
if TYPE_CHECKING:
1616
from typing import Any

sentry_sdk/integrations/aiohttp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
except ImportError:
4242
raise DidNotEnable("AIOHTTP not installed")
4343

44-
from sentry_sdk._types import TYPE_CHECKING
44+
from typing import TYPE_CHECKING
4545

4646
if TYPE_CHECKING:
4747
from aiohttp.web_request import Request

sentry_sdk/integrations/argv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from sentry_sdk.integrations import Integration
55
from sentry_sdk.scope import add_global_event_processor
66

7-
from sentry_sdk._types import TYPE_CHECKING
7+
from typing import TYPE_CHECKING
88

99
if TYPE_CHECKING:
1010
from typing import Optional

sentry_sdk/integrations/ariadne.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
event_from_exception,
1313
package_version,
1414
)
15-
from sentry_sdk._types import TYPE_CHECKING
1615

1716
try:
1817
# importing like this is necessary due to name shadowing in ariadne
@@ -21,6 +20,7 @@
2120
except ImportError:
2221
raise DidNotEnable("ariadne is not installed")
2322

23+
from typing import TYPE_CHECKING
2424

2525
if TYPE_CHECKING:
2626
from typing import Any, Dict, List, Optional

sentry_sdk/integrations/arq.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sys
22

33
import sentry_sdk
4-
from sentry_sdk._types import TYPE_CHECKING
54
from sentry_sdk.consts import OP, SPANSTATUS
65
from sentry_sdk.integrations import DidNotEnable, Integration
76
from sentry_sdk.integrations.logging import ignore_logger
@@ -24,6 +23,8 @@
2423
except ImportError:
2524
raise DidNotEnable("Arq is not installed")
2625

26+
from typing import TYPE_CHECKING
27+
2728
if TYPE_CHECKING:
2829
from typing import Any, Dict, Optional, Union
2930

sentry_sdk/integrations/asgi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from functools import partial
1111

1212
import sentry_sdk
13-
from sentry_sdk._types import TYPE_CHECKING
1413
from sentry_sdk.api import continue_trace
1514
from sentry_sdk.consts import OP
1615

@@ -37,6 +36,8 @@
3736
)
3837
from sentry_sdk.tracing import Transaction
3938

39+
from typing import TYPE_CHECKING
40+
4041
if TYPE_CHECKING:
4142
from typing import Any
4243
from typing import Callable

sentry_sdk/integrations/asyncio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import sentry_sdk
44
from sentry_sdk.consts import OP
55
from sentry_sdk.integrations import Integration, DidNotEnable
6-
from sentry_sdk._types import TYPE_CHECKING
76
from sentry_sdk.utils import event_from_exception, reraise
87

98
try:
@@ -12,6 +11,7 @@
1211
except ImportError:
1312
raise DidNotEnable("asyncio not available")
1413

14+
from typing import TYPE_CHECKING
1515

1616
if TYPE_CHECKING:
1717
from typing import Any

sentry_sdk/integrations/atexit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from sentry_sdk.utils import logger
77
from sentry_sdk.integrations import Integration
88
from sentry_sdk.utils import ensure_integration_enabled
9-
from sentry_sdk._types import TYPE_CHECKING
9+
10+
from typing import TYPE_CHECKING
1011

1112
if TYPE_CHECKING:
1213
from typing import Any

sentry_sdk/integrations/aws_lambda.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
)
2020
from sentry_sdk.integrations import Integration
2121
from sentry_sdk.integrations._wsgi_common import _filter_headers
22-
from sentry_sdk._types import TYPE_CHECKING
22+
23+
from typing import TYPE_CHECKING
2324

2425
if TYPE_CHECKING:
2526
from typing import Any

sentry_sdk/integrations/beam.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
event_from_exception,
1212
reraise,
1313
)
14-
from sentry_sdk._types import TYPE_CHECKING
14+
15+
from typing import TYPE_CHECKING
1516

1617
if TYPE_CHECKING:
1718
from typing import Any

sentry_sdk/integrations/boto3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
from sentry_sdk.consts import OP, SPANDATA
55
from sentry_sdk.integrations import Integration, DidNotEnable
66
from sentry_sdk.tracing import Span
7-
8-
from sentry_sdk._types import TYPE_CHECKING
97
from sentry_sdk.utils import (
108
capture_internal_exceptions,
119
ensure_integration_enabled,
1210
parse_url,
1311
parse_version,
1412
)
1513

14+
from typing import TYPE_CHECKING
15+
1616
if TYPE_CHECKING:
1717
from typing import Any
1818
from typing import Dict

sentry_sdk/integrations/bottle.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
from sentry_sdk.integrations import Integration, DidNotEnable
1111
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
1212
from sentry_sdk.integrations._wsgi_common import RequestExtractor
13-
from sentry_sdk._types import TYPE_CHECKING
13+
14+
from typing import TYPE_CHECKING
1415

1516
if TYPE_CHECKING:
1617
from sentry_sdk.integrations.wsgi import _ScopedResponse

sentry_sdk/integrations/celery/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch
1616
from sentry_sdk.integrations.logging import ignore_logger
1717
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, TRANSACTION_SOURCE_TASK
18-
from sentry_sdk._types import TYPE_CHECKING
1918
from sentry_sdk.tracing_utils import Baggage
2019
from sentry_sdk.utils import (
2120
capture_internal_exceptions,
@@ -24,6 +23,8 @@
2423
reraise,
2524
)
2625

26+
from typing import TYPE_CHECKING
27+
2728
if TYPE_CHECKING:
2829
from typing import Any
2930
from typing import Callable

sentry_sdk/integrations/celery/beat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
_get_humanized_interval,
66
_now_seconds_since_epoch,
77
)
8-
from sentry_sdk._types import TYPE_CHECKING
98
from sentry_sdk.utils import (
109
logger,
1110
match_regex_list,
1211
)
1312

13+
from typing import TYPE_CHECKING
14+
1415
if TYPE_CHECKING:
1516
from collections.abc import Callable
1617
from typing import Any, Optional, TypeVar, Union

sentry_sdk/integrations/celery/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import time
2-
from typing import cast
3-
4-
from sentry_sdk._types import TYPE_CHECKING
2+
from typing import TYPE_CHECKING, cast
53

64
if TYPE_CHECKING:
75
from typing import Any, Tuple

0 commit comments

Comments
 (0)