Skip to content

Commit 1e3e109

Browse files
authored
fix: Rename MYPY to TYPE_CHECKING (getsentry#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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 7 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)