Skip to content

Commit 1e3e109

Browse files
authored
fix: Rename MYPY to TYPE_CHECKING (#1934)
* fix: Rename MYPY to TYPE_CHECKING we have a lot of conditionals in our codebase that are supposed to separate the code that mypy is supposed to see from the code that we actually want to execute. In the specific case of sentry_sdk.configure_scope, this means that pyright does not handle with the overloads correctly because it only recognizes TYPE_CHECKING as a special variable name, not MYPY. Rename MYPY to TYPE_CHECKING so pyright typechecks configure_scope correctly. * reexport old alias
1 parent 888c0e1 commit 1e3e109

Some content is hidden

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

74 files changed

+161
-157
lines changed

scripts/init_serverless_sdk.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
import re
1111

1212
import sentry_sdk
13-
from sentry_sdk._types import MYPY
13+
from sentry_sdk._types import TYPE_CHECKING
1414
from sentry_sdk.utils import Dsn
1515
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
1616

17-
if MYPY:
17+
if TYPE_CHECKING:
1818
from typing import Any
1919

2020

sentry_sdk/_compat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import sys
22

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

5-
if MYPY:
5+
if TYPE_CHECKING:
66
from typing import Optional
77
from typing import Tuple
88
from typing import Any

sentry_sdk/_functools.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
from functools import partial
77

8-
from sentry_sdk._types import MYPY
8+
from sentry_sdk._types import TYPE_CHECKING
99

10-
if MYPY:
10+
if TYPE_CHECKING:
1111
from typing import Any
1212
from typing import Callable
1313

sentry_sdk/_queue.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
from collections import deque
1717
from time import time
1818

19-
from sentry_sdk._types import MYPY
19+
from sentry_sdk._types import TYPE_CHECKING
2020

21-
if MYPY:
21+
if TYPE_CHECKING:
2222
from typing import Any
2323

2424
__all__ = ["EmptyError", "FullError", "Queue"]

sentry_sdk/_types.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
try:
2-
from typing import TYPE_CHECKING as MYPY
2+
from typing import TYPE_CHECKING as TYPE_CHECKING
33
except ImportError:
4-
MYPY = False
4+
TYPE_CHECKING = False
55

66

7-
if MYPY:
7+
# Re-exported for compat, since code out there in the wild might use this variable.
8+
MYPY = TYPE_CHECKING
9+
10+
11+
if TYPE_CHECKING:
812
from types import TracebackType
913
from typing import Any
1014
from typing import Callable

sentry_sdk/api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from sentry_sdk.hub import Hub
44
from sentry_sdk.scope import Scope
55

6-
from sentry_sdk._types import MYPY
6+
from sentry_sdk._types import TYPE_CHECKING
77
from sentry_sdk.tracing import NoOpSpan
88

9-
if MYPY:
9+
if TYPE_CHECKING:
1010
from typing import Any
1111
from typing import Dict
1212
from typing import Optional

sentry_sdk/attachments.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import os
22
import mimetypes
33

4-
from sentry_sdk._types import MYPY
4+
from sentry_sdk._types import TYPE_CHECKING
55
from sentry_sdk.envelope import Item, PayloadRef
66

7-
if MYPY:
7+
if TYPE_CHECKING:
88
from typing import Optional, Union, Callable
99

1010

sentry_sdk/client.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
from sentry_sdk.envelope import Envelope
3131
from sentry_sdk.profiler import setup_profiler
3232

33-
from sentry_sdk._types import MYPY
33+
from sentry_sdk._types import TYPE_CHECKING
3434

35-
if MYPY:
35+
if TYPE_CHECKING:
3636
from typing import Any
3737
from typing import Callable
3838
from typing import Dict
@@ -523,9 +523,9 @@ def __exit__(self, exc_type, exc_value, tb):
523523
self.close()
524524

525525

526-
from sentry_sdk._types import MYPY
526+
from sentry_sdk._types import TYPE_CHECKING
527527

528-
if MYPY:
528+
if TYPE_CHECKING:
529529
# Make mypy, PyCharm and other static analyzers think `get_options` is a
530530
# type to have nicer autocompletion for params.
531531
#

sentry_sdk/consts.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from sentry_sdk._types import MYPY
1+
from sentry_sdk._types import TYPE_CHECKING
22

3-
if MYPY:
3+
if TYPE_CHECKING:
44
import sentry_sdk
55

66
from typing import Optional

sentry_sdk/envelope.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import mimetypes
44

55
from sentry_sdk._compat import text_type, PY2
6-
from sentry_sdk._types import MYPY
6+
from sentry_sdk._types import TYPE_CHECKING
77
from sentry_sdk.session import Session
88
from sentry_sdk.utils import json_dumps, capture_internal_exceptions
99

10-
if MYPY:
10+
if TYPE_CHECKING:
1111
from typing import Any
1212
from typing import Optional
1313
from typing import Union

sentry_sdk/hub.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
ContextVar,
1919
)
2020

21-
from sentry_sdk._types import MYPY
21+
from sentry_sdk._types import TYPE_CHECKING
2222

23-
if MYPY:
23+
if TYPE_CHECKING:
2424
from typing import Union
2525
from typing import Any
2626
from typing import Optional
@@ -125,9 +125,9 @@ def _init(*args, **kwargs):
125125
return rv
126126

127127

128-
from sentry_sdk._types import MYPY
128+
from sentry_sdk._types import TYPE_CHECKING
129129

130-
if MYPY:
130+
if TYPE_CHECKING:
131131
# Make mypy, PyCharm and other static analyzers think `init` is a type to
132132
# have nicer autocompletion for params.
133133
#
@@ -223,7 +223,7 @@ class Hub(with_metaclass(HubMeta)): # type: ignore
223223

224224
# Mypy doesn't pick up on the metaclass.
225225

226-
if MYPY:
226+
if TYPE_CHECKING:
227227
current = None # type: Hub
228228
main = None # type: Hub
229229

sentry_sdk/integrations/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from sentry_sdk._compat import iteritems
77
from sentry_sdk.utils import logger
88

9-
from sentry_sdk._types import MYPY
9+
from sentry_sdk._types import TYPE_CHECKING
1010

11-
if MYPY:
11+
if TYPE_CHECKING:
1212
from typing import Callable
1313
from typing import Dict
1414
from typing import Iterator

sentry_sdk/integrations/_wsgi_common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from sentry_sdk.utils import AnnotatedValue
55
from sentry_sdk._compat import text_type, iteritems
66

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

9-
if MYPY:
9+
if TYPE_CHECKING:
1010
import sentry_sdk
1111

1212
from typing import Any

sentry_sdk/integrations/aiohttp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
except ImportError:
3030
raise DidNotEnable("AIOHTTP not installed")
3131

32-
from sentry_sdk._types import MYPY
32+
from sentry_sdk._types import TYPE_CHECKING
3333

34-
if MYPY:
34+
if TYPE_CHECKING:
3535
from aiohttp.web_request import Request
3636
from aiohttp.abc import AbstractMatchInfo
3737
from typing import Any

sentry_sdk/integrations/argv.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from sentry_sdk.integrations import Integration
77
from sentry_sdk.scope import add_global_event_processor
88

9-
from sentry_sdk._types import MYPY
9+
from sentry_sdk._types import TYPE_CHECKING
1010

11-
if MYPY:
11+
if TYPE_CHECKING:
1212
from typing import Optional
1313

1414
from sentry_sdk._types import Event, Hint

sentry_sdk/integrations/arq.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44

55
from sentry_sdk._compat import reraise
6-
from sentry_sdk._types import MYPY
6+
from sentry_sdk._types import TYPE_CHECKING
77
from sentry_sdk import Hub
88
from sentry_sdk.consts import OP
99
from sentry_sdk.hub import _should_send_default_pii
@@ -24,7 +24,7 @@
2424
except ImportError:
2525
raise DidNotEnable("Arq is not installed")
2626

27-
if MYPY:
27+
if TYPE_CHECKING:
2828
from typing import Any, Dict, Optional
2929

3030
from sentry_sdk._types import EventProcessor, Event, ExcInfo, Hint

sentry_sdk/integrations/asgi.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import urllib
1010

1111
from sentry_sdk._functools import partial
12-
from sentry_sdk._types import MYPY
12+
from sentry_sdk._types import TYPE_CHECKING
1313
from sentry_sdk.consts import OP
1414
from sentry_sdk.hub import Hub, _should_send_default_pii
1515
from sentry_sdk.integrations._wsgi_common import _filter_headers
@@ -29,7 +29,7 @@
2929
)
3030
from sentry_sdk.tracing import Transaction
3131

32-
if MYPY:
32+
if TYPE_CHECKING:
3333
from typing import Dict
3434
from typing import Any
3535
from typing import Optional

sentry_sdk/integrations/asyncio.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sentry_sdk.consts import OP
66
from sentry_sdk.hub import Hub
77
from sentry_sdk.integrations import Integration, DidNotEnable
8-
from sentry_sdk._types import MYPY
8+
from sentry_sdk._types import TYPE_CHECKING
99
from sentry_sdk.utils import event_from_exception
1010

1111
try:
@@ -15,7 +15,7 @@
1515
raise DidNotEnable("asyncio not available")
1616

1717

18-
if MYPY:
18+
if TYPE_CHECKING:
1919
from typing import Any
2020

2121
from sentry_sdk._types import ExcInfo

sentry_sdk/integrations/atexit.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from sentry_sdk.utils import logger
99
from sentry_sdk.integrations import Integration
1010

11-
from sentry_sdk._types import MYPY
11+
from sentry_sdk._types import TYPE_CHECKING
1212

13-
if MYPY:
13+
if TYPE_CHECKING:
1414

1515
from typing import Any
1616
from typing import Optional

sentry_sdk/integrations/aws_lambda.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
from sentry_sdk.integrations import Integration
1717
from sentry_sdk.integrations._wsgi_common import _filter_headers
1818

19-
from sentry_sdk._types import MYPY
19+
from sentry_sdk._types import TYPE_CHECKING
2020

21-
if MYPY:
21+
if TYPE_CHECKING:
2222
from typing import Any
2323
from typing import TypeVar
2424
from typing import Callable

sentry_sdk/integrations/beam.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
from sentry_sdk.utils import capture_internal_exceptions, event_from_exception
1010
from sentry_sdk.integrations import Integration
1111
from sentry_sdk.integrations.logging import ignore_logger
12-
from sentry_sdk._types import MYPY
12+
from sentry_sdk._types import TYPE_CHECKING
1313

14-
if MYPY:
14+
if TYPE_CHECKING:
1515
from typing import Any
1616
from typing import Iterator
1717
from typing import TypeVar

sentry_sdk/integrations/boto3.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from sentry_sdk.tracing import Span
77

88
from sentry_sdk._functools import partial
9-
from sentry_sdk._types import MYPY
9+
from sentry_sdk._types import TYPE_CHECKING
1010
from sentry_sdk.utils import parse_url
1111

12-
if MYPY:
12+
if TYPE_CHECKING:
1313
from typing import Any
1414
from typing import Dict
1515
from typing import Optional

sentry_sdk/integrations/bottle.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
1212
from sentry_sdk.integrations._wsgi_common import RequestExtractor
1313

14-
from sentry_sdk._types import MYPY
14+
from sentry_sdk._types import TYPE_CHECKING
1515

16-
if MYPY:
16+
if TYPE_CHECKING:
1717
from sentry_sdk.integrations.wsgi import _ScopedResponse
1818
from typing import Any
1919
from typing import Dict

sentry_sdk/integrations/celery.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
from sentry_sdk._compat import reraise
1414
from sentry_sdk.integrations import Integration, DidNotEnable
1515
from sentry_sdk.integrations.logging import ignore_logger
16-
from sentry_sdk._types import MYPY
16+
from sentry_sdk._types import TYPE_CHECKING
1717
from sentry_sdk._functools import wraps
1818

19-
if MYPY:
19+
if TYPE_CHECKING:
2020
from typing import Any
2121
from typing import TypeVar
2222
from typing import Callable

sentry_sdk/integrations/chalice.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
capture_internal_exceptions,
1010
event_from_exception,
1111
)
12-
from sentry_sdk._types import MYPY
12+
from sentry_sdk._types import TYPE_CHECKING
1313
from sentry_sdk._functools import wraps
1414

1515
import chalice # type: ignore
1616
from chalice import Chalice, ChaliceViewError
1717
from chalice.app import EventSourceHandler as ChaliceEventSourceHandler # type: ignore
1818

19-
if MYPY:
19+
if TYPE_CHECKING:
2020
from typing import Any
2121
from typing import Dict
2222
from typing import TypeVar

sentry_sdk/integrations/cloud_resource_context.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from sentry_sdk.api import set_context
66
from sentry_sdk.utils import logger
77

8-
from sentry_sdk._types import MYPY
8+
from sentry_sdk._types import TYPE_CHECKING
99

10-
if MYPY:
10+
if TYPE_CHECKING:
1111
from typing import Dict
1212

1313

sentry_sdk/integrations/dedupe.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from sentry_sdk.integrations import Integration
44
from sentry_sdk.scope import add_global_event_processor
55

6-
from sentry_sdk._types import MYPY
6+
from sentry_sdk._types import TYPE_CHECKING
77

8-
if MYPY:
8+
if TYPE_CHECKING:
99
from typing import Optional
1010

1111
from sentry_sdk._types import Event, Hint

0 commit comments

Comments
 (0)