diff --git a/scripts/init_serverless_sdk.py b/scripts/init_serverless_sdk.py index 7fc7f64d05..05dd8c767a 100644 --- a/scripts/init_serverless_sdk.py +++ b/scripts/init_serverless_sdk.py @@ -10,11 +10,11 @@ import re import sentry_sdk -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.utils import Dsn from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration -if MYPY: +if TYPE_CHECKING: from typing import Any diff --git a/sentry_sdk/_compat.py b/sentry_sdk/_compat.py index 62abfd1622..4fa489569b 100644 --- a/sentry_sdk/_compat.py +++ b/sentry_sdk/_compat.py @@ -1,8 +1,8 @@ import sys -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Optional from typing import Tuple from typing import Any diff --git a/sentry_sdk/_functools.py b/sentry_sdk/_functools.py index 8dcf79caaa..ceb603c052 100644 --- a/sentry_sdk/_functools.py +++ b/sentry_sdk/_functools.py @@ -5,9 +5,9 @@ from functools import partial -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Callable diff --git a/sentry_sdk/_queue.py b/sentry_sdk/_queue.py index fc845f70d1..44744ca1c6 100644 --- a/sentry_sdk/_queue.py +++ b/sentry_sdk/_queue.py @@ -16,9 +16,9 @@ from collections import deque from time import time -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any __all__ = ["EmptyError", "FullError", "Queue"] diff --git a/sentry_sdk/_types.py b/sentry_sdk/_types.py index 7064192977..2c4a703cb5 100644 --- a/sentry_sdk/_types.py +++ b/sentry_sdk/_types.py @@ -1,10 +1,14 @@ try: - from typing import TYPE_CHECKING as MYPY + from typing import TYPE_CHECKING as TYPE_CHECKING except ImportError: - MYPY = False + TYPE_CHECKING = False -if MYPY: +# Re-exported for compat, since code out there in the wild might use this variable. +MYPY = TYPE_CHECKING + + +if TYPE_CHECKING: from types import TracebackType from typing import Any from typing import Callable diff --git a/sentry_sdk/api.py b/sentry_sdk/api.py index 70352d465d..1681ef48a0 100644 --- a/sentry_sdk/api.py +++ b/sentry_sdk/api.py @@ -3,10 +3,10 @@ from sentry_sdk.hub import Hub from sentry_sdk.scope import Scope -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.tracing import NoOpSpan -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Dict from typing import Optional diff --git a/sentry_sdk/attachments.py b/sentry_sdk/attachments.py index b7b6b0b45b..c15afd447b 100644 --- a/sentry_sdk/attachments.py +++ b/sentry_sdk/attachments.py @@ -1,10 +1,10 @@ import os import mimetypes -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.envelope import Item, PayloadRef -if MYPY: +if TYPE_CHECKING: from typing import Optional, Union, Callable diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index 3c94ea6bf0..38b64e3798 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -30,9 +30,9 @@ from sentry_sdk.envelope import Envelope from sentry_sdk.profiler import setup_profiler -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Callable from typing import Dict @@ -523,9 +523,9 @@ def __exit__(self, exc_type, exc_value, tb): self.close() -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: # Make mypy, PyCharm and other static analyzers think `get_options` is a # type to have nicer autocompletion for params. # diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 99f70cdc7f..bf576a63e8 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -1,6 +1,6 @@ -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: import sentry_sdk from typing import Optional diff --git a/sentry_sdk/envelope.py b/sentry_sdk/envelope.py index 24eb87b91f..2fb1bae387 100644 --- a/sentry_sdk/envelope.py +++ b/sentry_sdk/envelope.py @@ -3,11 +3,11 @@ import mimetypes from sentry_sdk._compat import text_type, PY2 -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.session import Session from sentry_sdk.utils import json_dumps, capture_internal_exceptions -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Optional from typing import Union diff --git a/sentry_sdk/hub.py b/sentry_sdk/hub.py index 6757b24b77..0f2d43ab2d 100644 --- a/sentry_sdk/hub.py +++ b/sentry_sdk/hub.py @@ -18,9 +18,9 @@ ContextVar, ) -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Union from typing import Any from typing import Optional @@ -125,9 +125,9 @@ def _init(*args, **kwargs): return rv -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: # Make mypy, PyCharm and other static analyzers think `init` is a type to # have nicer autocompletion for params. # @@ -223,7 +223,7 @@ class Hub(with_metaclass(HubMeta)): # type: ignore # Mypy doesn't pick up on the metaclass. - if MYPY: + if TYPE_CHECKING: current = None # type: Hub main = None # type: Hub diff --git a/sentry_sdk/integrations/__init__.py b/sentry_sdk/integrations/__init__.py index 8d32741542..a2bbc04260 100644 --- a/sentry_sdk/integrations/__init__.py +++ b/sentry_sdk/integrations/__init__.py @@ -6,9 +6,9 @@ from sentry_sdk._compat import iteritems from sentry_sdk.utils import logger -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Callable from typing import Dict from typing import Iterator diff --git a/sentry_sdk/integrations/_wsgi_common.py b/sentry_sdk/integrations/_wsgi_common.py index 1b7b222f18..21f7ba1a6e 100644 --- a/sentry_sdk/integrations/_wsgi_common.py +++ b/sentry_sdk/integrations/_wsgi_common.py @@ -4,9 +4,9 @@ from sentry_sdk.utils import AnnotatedValue from sentry_sdk._compat import text_type, iteritems -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: import sentry_sdk from typing import Any diff --git a/sentry_sdk/integrations/aiohttp.py b/sentry_sdk/integrations/aiohttp.py index d1728f6edb..8b6c783530 100644 --- a/sentry_sdk/integrations/aiohttp.py +++ b/sentry_sdk/integrations/aiohttp.py @@ -29,9 +29,9 @@ except ImportError: raise DidNotEnable("AIOHTTP not installed") -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from aiohttp.web_request import Request from aiohttp.abc import AbstractMatchInfo from typing import Any diff --git a/sentry_sdk/integrations/argv.py b/sentry_sdk/integrations/argv.py index f005521d32..fea08619d5 100644 --- a/sentry_sdk/integrations/argv.py +++ b/sentry_sdk/integrations/argv.py @@ -6,9 +6,9 @@ from sentry_sdk.integrations import Integration from sentry_sdk.scope import add_global_event_processor -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Optional from sentry_sdk._types import Event, Hint diff --git a/sentry_sdk/integrations/arq.py b/sentry_sdk/integrations/arq.py index 195272a4c7..1a6ba0e7c4 100644 --- a/sentry_sdk/integrations/arq.py +++ b/sentry_sdk/integrations/arq.py @@ -3,7 +3,7 @@ import sys from sentry_sdk._compat import reraise -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk import Hub from sentry_sdk.consts import OP from sentry_sdk.hub import _should_send_default_pii @@ -24,7 +24,7 @@ except ImportError: raise DidNotEnable("Arq is not installed") -if MYPY: +if TYPE_CHECKING: from typing import Any, Dict, Optional from sentry_sdk._types import EventProcessor, Event, ExcInfo, Hint diff --git a/sentry_sdk/integrations/asgi.py b/sentry_sdk/integrations/asgi.py index 6952957618..6fd4026ada 100644 --- a/sentry_sdk/integrations/asgi.py +++ b/sentry_sdk/integrations/asgi.py @@ -9,7 +9,7 @@ import urllib from sentry_sdk._functools import partial -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.consts import OP from sentry_sdk.hub import Hub, _should_send_default_pii from sentry_sdk.integrations._wsgi_common import _filter_headers @@ -29,7 +29,7 @@ ) from sentry_sdk.tracing import Transaction -if MYPY: +if TYPE_CHECKING: from typing import Dict from typing import Any from typing import Optional diff --git a/sentry_sdk/integrations/asyncio.py b/sentry_sdk/integrations/asyncio.py index 4f33965539..c31364b940 100644 --- a/sentry_sdk/integrations/asyncio.py +++ b/sentry_sdk/integrations/asyncio.py @@ -5,7 +5,7 @@ from sentry_sdk.consts import OP from sentry_sdk.hub import Hub from sentry_sdk.integrations import Integration, DidNotEnable -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.utils import event_from_exception try: @@ -15,7 +15,7 @@ raise DidNotEnable("asyncio not available") -if MYPY: +if TYPE_CHECKING: from typing import Any from sentry_sdk._types import ExcInfo diff --git a/sentry_sdk/integrations/atexit.py b/sentry_sdk/integrations/atexit.py index 18fe657bff..36d7025a1e 100644 --- a/sentry_sdk/integrations/atexit.py +++ b/sentry_sdk/integrations/atexit.py @@ -8,9 +8,9 @@ from sentry_sdk.utils import logger from sentry_sdk.integrations import Integration -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Optional diff --git a/sentry_sdk/integrations/aws_lambda.py b/sentry_sdk/integrations/aws_lambda.py index 6017adfa7b..1f511b99b0 100644 --- a/sentry_sdk/integrations/aws_lambda.py +++ b/sentry_sdk/integrations/aws_lambda.py @@ -16,9 +16,9 @@ from sentry_sdk.integrations import Integration from sentry_sdk.integrations._wsgi_common import _filter_headers -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import TypeVar from typing import Callable diff --git a/sentry_sdk/integrations/beam.py b/sentry_sdk/integrations/beam.py index 30faa3814f..ea45087d05 100644 --- a/sentry_sdk/integrations/beam.py +++ b/sentry_sdk/integrations/beam.py @@ -9,9 +9,9 @@ from sentry_sdk.utils import capture_internal_exceptions, event_from_exception from sentry_sdk.integrations import Integration from sentry_sdk.integrations.logging import ignore_logger -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Iterator from typing import TypeVar diff --git a/sentry_sdk/integrations/boto3.py b/sentry_sdk/integrations/boto3.py index d86628402e..ac07394177 100644 --- a/sentry_sdk/integrations/boto3.py +++ b/sentry_sdk/integrations/boto3.py @@ -6,10 +6,10 @@ from sentry_sdk.tracing import Span from sentry_sdk._functools import partial -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.utils import parse_url -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Dict from typing import Optional diff --git a/sentry_sdk/integrations/bottle.py b/sentry_sdk/integrations/bottle.py index 271fc150b1..71c4f127f6 100644 --- a/sentry_sdk/integrations/bottle.py +++ b/sentry_sdk/integrations/bottle.py @@ -11,9 +11,9 @@ from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware from sentry_sdk.integrations._wsgi_common import RequestExtractor -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from sentry_sdk.integrations.wsgi import _ScopedResponse from typing import Any from typing import Dict diff --git a/sentry_sdk/integrations/celery.py b/sentry_sdk/integrations/celery.py index ea865b35a4..f8541fa0b2 100644 --- a/sentry_sdk/integrations/celery.py +++ b/sentry_sdk/integrations/celery.py @@ -13,10 +13,10 @@ from sentry_sdk._compat import reraise from sentry_sdk.integrations import Integration, DidNotEnable from sentry_sdk.integrations.logging import ignore_logger -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk._functools import wraps -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import TypeVar from typing import Callable diff --git a/sentry_sdk/integrations/chalice.py b/sentry_sdk/integrations/chalice.py index 80069b2951..6381850560 100644 --- a/sentry_sdk/integrations/chalice.py +++ b/sentry_sdk/integrations/chalice.py @@ -9,14 +9,14 @@ capture_internal_exceptions, event_from_exception, ) -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk._functools import wraps import chalice # type: ignore from chalice import Chalice, ChaliceViewError from chalice.app import EventSourceHandler as ChaliceEventSourceHandler # type: ignore -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Dict from typing import TypeVar diff --git a/sentry_sdk/integrations/cloud_resource_context.py b/sentry_sdk/integrations/cloud_resource_context.py index c7b96c35a8..b8e85c5f19 100644 --- a/sentry_sdk/integrations/cloud_resource_context.py +++ b/sentry_sdk/integrations/cloud_resource_context.py @@ -5,9 +5,9 @@ from sentry_sdk.api import set_context from sentry_sdk.utils import logger -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Dict diff --git a/sentry_sdk/integrations/dedupe.py b/sentry_sdk/integrations/dedupe.py index b023df2042..04208f608a 100644 --- a/sentry_sdk/integrations/dedupe.py +++ b/sentry_sdk/integrations/dedupe.py @@ -3,9 +3,9 @@ from sentry_sdk.integrations import Integration from sentry_sdk.scope import add_global_event_processor -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Optional from sentry_sdk._types import Event, Hint diff --git a/sentry_sdk/integrations/django/__init__.py b/sentry_sdk/integrations/django/__init__.py index d905981a0f..ab68a396c7 100644 --- a/sentry_sdk/integrations/django/__init__.py +++ b/sentry_sdk/integrations/django/__init__.py @@ -5,7 +5,7 @@ import threading import weakref -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.consts import OP from sentry_sdk.hub import Hub, _should_send_default_pii from sentry_sdk.scope import add_global_event_processor @@ -51,7 +51,7 @@ from sentry_sdk.integrations.django.views import patch_views -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Callable from typing import Dict diff --git a/sentry_sdk/integrations/django/asgi.py b/sentry_sdk/integrations/django/asgi.py index 721b2444cf..7f40671526 100644 --- a/sentry_sdk/integrations/django/asgi.py +++ b/sentry_sdk/integrations/django/asgi.py @@ -9,12 +9,12 @@ import asyncio from sentry_sdk import Hub, _functools -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.consts import OP from sentry_sdk.integrations.asgi import SentryAsgiMiddleware -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Union from typing import Callable @@ -109,7 +109,7 @@ def _asgi_middleware_mixin_factory(_check_middleware_span): """ class SentryASGIMixin: - if MYPY: + if TYPE_CHECKING: _inner = None def __init__(self, get_response): diff --git a/sentry_sdk/integrations/django/middleware.py b/sentry_sdk/integrations/django/middleware.py index 35680e10b1..5ef0b0838e 100644 --- a/sentry_sdk/integrations/django/middleware.py +++ b/sentry_sdk/integrations/django/middleware.py @@ -6,7 +6,7 @@ from sentry_sdk import Hub from sentry_sdk._functools import wraps -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.consts import OP from sentry_sdk.utils import ( ContextVar, @@ -14,7 +14,7 @@ capture_internal_exceptions, ) -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Callable from typing import Optional diff --git a/sentry_sdk/integrations/django/signals_handlers.py b/sentry_sdk/integrations/django/signals_handlers.py index 194c81837e..dd1893dcd6 100644 --- a/sentry_sdk/integrations/django/signals_handlers.py +++ b/sentry_sdk/integrations/django/signals_handlers.py @@ -5,11 +5,11 @@ from sentry_sdk import Hub from sentry_sdk._functools import wraps -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.consts import OP -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Callable from typing import List diff --git a/sentry_sdk/integrations/django/templates.py b/sentry_sdk/integrations/django/templates.py index 39279be4ce..80be0977e6 100644 --- a/sentry_sdk/integrations/django/templates.py +++ b/sentry_sdk/integrations/django/templates.py @@ -2,10 +2,10 @@ from django import VERSION as DJANGO_VERSION from sentry_sdk import _functools, Hub -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.consts import OP -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Dict from typing import Optional diff --git a/sentry_sdk/integrations/django/transactions.py b/sentry_sdk/integrations/django/transactions.py index 8b6fc95f99..91349c4bf9 100644 --- a/sentry_sdk/integrations/django/transactions.py +++ b/sentry_sdk/integrations/django/transactions.py @@ -7,9 +7,9 @@ import re -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from django.urls.resolvers import URLResolver from typing import Dict from typing import List diff --git a/sentry_sdk/integrations/django/views.py b/sentry_sdk/integrations/django/views.py index 6c03b33edb..716d738ce8 100644 --- a/sentry_sdk/integrations/django/views.py +++ b/sentry_sdk/integrations/django/views.py @@ -1,9 +1,9 @@ from sentry_sdk.consts import OP from sentry_sdk.hub import Hub -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk import _functools -if MYPY: +if TYPE_CHECKING: from typing import Any diff --git a/sentry_sdk/integrations/excepthook.py b/sentry_sdk/integrations/excepthook.py index 1f16ff0b06..514e082b31 100644 --- a/sentry_sdk/integrations/excepthook.py +++ b/sentry_sdk/integrations/excepthook.py @@ -4,9 +4,9 @@ from sentry_sdk.utils import capture_internal_exceptions, event_from_exception from sentry_sdk.integrations import Integration -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Callable from typing import Any from typing import Type diff --git a/sentry_sdk/integrations/executing.py b/sentry_sdk/integrations/executing.py index 4fbf729bb1..e8636b61f8 100644 --- a/sentry_sdk/integrations/executing.py +++ b/sentry_sdk/integrations/executing.py @@ -1,12 +1,12 @@ from __future__ import absolute_import from sentry_sdk import Hub -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.integrations import Integration, DidNotEnable from sentry_sdk.scope import add_global_event_processor from sentry_sdk.utils import walk_exception_chain, iter_stacks -if MYPY: +if TYPE_CHECKING: from typing import Optional from sentry_sdk._types import Event, Hint diff --git a/sentry_sdk/integrations/falcon.py b/sentry_sdk/integrations/falcon.py index fd4648a4b6..f4bc361fa7 100644 --- a/sentry_sdk/integrations/falcon.py +++ b/sentry_sdk/integrations/falcon.py @@ -10,9 +10,9 @@ event_from_exception, ) -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Dict from typing import Optional diff --git a/sentry_sdk/integrations/fastapi.py b/sentry_sdk/integrations/fastapi.py index 5dde0e7d37..d43825e1b2 100644 --- a/sentry_sdk/integrations/fastapi.py +++ b/sentry_sdk/integrations/fastapi.py @@ -1,12 +1,12 @@ import asyncio -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.hub import Hub, _should_send_default_pii from sentry_sdk.integrations import DidNotEnable from sentry_sdk.tracing import SOURCE_FOR_STYLE, TRANSACTION_SOURCE_ROUTE from sentry_sdk.utils import transaction_from_function -if MYPY: +if TYPE_CHECKING: from typing import Any, Callable, Dict from sentry_sdk.scope import Scope diff --git a/sentry_sdk/integrations/flask.py b/sentry_sdk/integrations/flask.py index e1755f548b..a795a820c9 100644 --- a/sentry_sdk/integrations/flask.py +++ b/sentry_sdk/integrations/flask.py @@ -1,6 +1,6 @@ from __future__ import absolute_import -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.hub import Hub, _should_send_default_pii from sentry_sdk.integrations import DidNotEnable, Integration from sentry_sdk.integrations._wsgi_common import RequestExtractor @@ -12,7 +12,7 @@ event_from_exception, ) -if MYPY: +if TYPE_CHECKING: from typing import Any, Callable, Dict, Union from sentry_sdk._types import EventProcessor diff --git a/sentry_sdk/integrations/gcp.py b/sentry_sdk/integrations/gcp.py index a69637a409..5ecb26af15 100644 --- a/sentry_sdk/integrations/gcp.py +++ b/sentry_sdk/integrations/gcp.py @@ -16,13 +16,13 @@ from sentry_sdk.integrations import Integration from sentry_sdk.integrations._wsgi_common import _filter_headers -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING # Constants TIMEOUT_WARNING_BUFFER = 1.5 # Buffer time required to send timeout warning to Sentry MILLIS_TO_SECONDS = 1000.0 -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import TypeVar from typing import Callable diff --git a/sentry_sdk/integrations/gnu_backtrace.py b/sentry_sdk/integrations/gnu_backtrace.py index e0ec110547..ad9c437878 100644 --- a/sentry_sdk/integrations/gnu_backtrace.py +++ b/sentry_sdk/integrations/gnu_backtrace.py @@ -5,9 +5,9 @@ from sentry_sdk.scope import add_global_event_processor from sentry_sdk.utils import capture_internal_exceptions -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Dict diff --git a/sentry_sdk/integrations/httpx.py b/sentry_sdk/integrations/httpx.py index 961ef25b02..4d3a7e8e22 100644 --- a/sentry_sdk/integrations/httpx.py +++ b/sentry_sdk/integrations/httpx.py @@ -4,9 +4,9 @@ from sentry_sdk.tracing_utils import should_propagate_trace from sentry_sdk.utils import logger, parse_url -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any diff --git a/sentry_sdk/integrations/huey.py b/sentry_sdk/integrations/huey.py index 74ce4d35d5..7c3fcbc70c 100644 --- a/sentry_sdk/integrations/huey.py +++ b/sentry_sdk/integrations/huey.py @@ -4,7 +4,7 @@ from datetime import datetime from sentry_sdk._compat import reraise -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk import Hub from sentry_sdk.consts import OP from sentry_sdk.hub import _should_send_default_pii @@ -16,7 +16,7 @@ SENSITIVE_DATA_SUBSTITUTE, ) -if MYPY: +if TYPE_CHECKING: from typing import Any, Callable, Optional, Union, TypeVar from sentry_sdk._types import EventProcessor, Event, Hint diff --git a/sentry_sdk/integrations/logging.py b/sentry_sdk/integrations/logging.py index 1d48922076..782180eea7 100644 --- a/sentry_sdk/integrations/logging.py +++ b/sentry_sdk/integrations/logging.py @@ -14,9 +14,9 @@ from sentry_sdk.integrations import Integration from sentry_sdk._compat import iteritems -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from logging import LogRecord from typing import Any from typing import Dict diff --git a/sentry_sdk/integrations/modules.py b/sentry_sdk/integrations/modules.py index 3d78cb89bb..c9066ebda6 100644 --- a/sentry_sdk/integrations/modules.py +++ b/sentry_sdk/integrations/modules.py @@ -4,9 +4,9 @@ from sentry_sdk.integrations import Integration from sentry_sdk.scope import add_global_event_processor -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Dict from typing import Tuple diff --git a/sentry_sdk/integrations/opentelemetry/propagator.py b/sentry_sdk/integrations/opentelemetry/propagator.py index 7b2a88e347..3e1f696939 100644 --- a/sentry_sdk/integrations/opentelemetry/propagator.py +++ b/sentry_sdk/integrations/opentelemetry/propagator.py @@ -30,9 +30,9 @@ SENTRY_TRACE_HEADER_NAME, ) from sentry_sdk.tracing_utils import Baggage, extract_sentrytrace_data -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Optional from typing import Set diff --git a/sentry_sdk/integrations/opentelemetry/span_processor.py b/sentry_sdk/integrations/opentelemetry/span_processor.py index 0017708a97..2c50082ff2 100644 --- a/sentry_sdk/integrations/opentelemetry/span_processor.py +++ b/sentry_sdk/integrations/opentelemetry/span_processor.py @@ -24,11 +24,11 @@ from sentry_sdk.scope import add_global_event_processor from sentry_sdk.tracing import Transaction, Span as SentrySpan from sentry_sdk.utils import Dsn -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from urllib3.util import parse_url as urlparse # type: ignore -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Dict from typing import Union diff --git a/sentry_sdk/integrations/pure_eval.py b/sentry_sdk/integrations/pure_eval.py index c804447796..5a2419c267 100644 --- a/sentry_sdk/integrations/pure_eval.py +++ b/sentry_sdk/integrations/pure_eval.py @@ -3,12 +3,12 @@ import ast from sentry_sdk import Hub, serializer -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.integrations import Integration, DidNotEnable from sentry_sdk.scope import add_global_event_processor from sentry_sdk.utils import walk_exception_chain, iter_stacks -if MYPY: +if TYPE_CHECKING: from typing import Optional, Dict, Any, Tuple, List from types import FrameType diff --git a/sentry_sdk/integrations/pymongo.py b/sentry_sdk/integrations/pymongo.py index ca4669ec9e..0a94d46813 100644 --- a/sentry_sdk/integrations/pymongo.py +++ b/sentry_sdk/integrations/pymongo.py @@ -7,14 +7,14 @@ from sentry_sdk.tracing import Span from sentry_sdk.utils import capture_internal_exceptions -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING try: from pymongo import monitoring except ImportError: raise DidNotEnable("Pymongo not installed") -if MYPY: +if TYPE_CHECKING: from typing import Any, Dict, Union from pymongo.monitoring import ( diff --git a/sentry_sdk/integrations/pyramid.py b/sentry_sdk/integrations/pyramid.py index 1e234fcffd..6bfed0318f 100644 --- a/sentry_sdk/integrations/pyramid.py +++ b/sentry_sdk/integrations/pyramid.py @@ -23,9 +23,9 @@ except ImportError: raise DidNotEnable("Pyramid not installed") -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from pyramid.response import Response from typing import Any from sentry_sdk.integrations.wsgi import _ScopedResponse diff --git a/sentry_sdk/integrations/quart.py b/sentry_sdk/integrations/quart.py index e1d4228651..9525f435b3 100644 --- a/sentry_sdk/integrations/quart.py +++ b/sentry_sdk/integrations/quart.py @@ -11,9 +11,9 @@ event_from_exception, ) -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Dict from typing import Union diff --git a/sentry_sdk/integrations/redis.py b/sentry_sdk/integrations/redis.py index aae5647f3d..5a15da1060 100644 --- a/sentry_sdk/integrations/redis.py +++ b/sentry_sdk/integrations/redis.py @@ -5,9 +5,9 @@ from sentry_sdk.utils import capture_internal_exceptions, logger from sentry_sdk.integrations import Integration, DidNotEnable -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any, Sequence _SINGLE_KEY_COMMANDS = frozenset( diff --git a/sentry_sdk/integrations/rq.py b/sentry_sdk/integrations/rq.py index 3b74d8f9be..2696cbff3c 100644 --- a/sentry_sdk/integrations/rq.py +++ b/sentry_sdk/integrations/rq.py @@ -21,9 +21,9 @@ except ImportError: raise DidNotEnable("RQ not installed") -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any, Callable, Dict from sentry_sdk._types import EventProcessor diff --git a/sentry_sdk/integrations/sanic.py b/sentry_sdk/integrations/sanic.py index 8892f93ed7..e6838ab9b0 100644 --- a/sentry_sdk/integrations/sanic.py +++ b/sentry_sdk/integrations/sanic.py @@ -15,9 +15,9 @@ from sentry_sdk.integrations._wsgi_common import RequestExtractor, _filter_headers from sentry_sdk.integrations.logging import ignore_logger -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Callable from typing import Optional diff --git a/sentry_sdk/integrations/serverless.py b/sentry_sdk/integrations/serverless.py index c22fbfd37f..534034547a 100644 --- a/sentry_sdk/integrations/serverless.py +++ b/sentry_sdk/integrations/serverless.py @@ -6,9 +6,9 @@ from sentry_sdk._functools import wraps -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Callable from typing import TypeVar diff --git a/sentry_sdk/integrations/spark/spark_driver.py b/sentry_sdk/integrations/spark/spark_driver.py index ea43c37821..b3085fc4af 100644 --- a/sentry_sdk/integrations/spark/spark_driver.py +++ b/sentry_sdk/integrations/spark/spark_driver.py @@ -3,9 +3,9 @@ from sentry_sdk.integrations import Integration from sentry_sdk.utils import capture_internal_exceptions -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Optional diff --git a/sentry_sdk/integrations/spark/spark_worker.py b/sentry_sdk/integrations/spark/spark_worker.py index 2c27647dab..cd4eb0f28b 100644 --- a/sentry_sdk/integrations/spark/spark_worker.py +++ b/sentry_sdk/integrations/spark/spark_worker.py @@ -13,9 +13,9 @@ event_hint_with_exc_info, ) -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Optional diff --git a/sentry_sdk/integrations/sqlalchemy.py b/sentry_sdk/integrations/sqlalchemy.py index 68e671cd92..64e90aa187 100644 --- a/sentry_sdk/integrations/sqlalchemy.py +++ b/sentry_sdk/integrations/sqlalchemy.py @@ -2,7 +2,7 @@ import re -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.hub import Hub from sentry_sdk.integrations import Integration, DidNotEnable from sentry_sdk.tracing_utils import record_sql_queries @@ -14,7 +14,7 @@ except ImportError: raise DidNotEnable("SQLAlchemy not installed.") -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import ContextManager from typing import Optional diff --git a/sentry_sdk/integrations/starlette.py b/sentry_sdk/integrations/starlette.py index 7b213f186b..a49f0bd67c 100644 --- a/sentry_sdk/integrations/starlette.py +++ b/sentry_sdk/integrations/starlette.py @@ -4,7 +4,7 @@ import functools from sentry_sdk._compat import iteritems -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.consts import OP from sentry_sdk.hub import Hub, _should_send_default_pii from sentry_sdk.integrations import DidNotEnable, Integration @@ -21,7 +21,7 @@ transaction_from_function, ) -if MYPY: +if TYPE_CHECKING: from typing import Any, Awaitable, Callable, Dict, Optional from sentry_sdk.scope import Scope as SentryScope diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index 280f7ced47..f4218b9ed4 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -15,9 +15,9 @@ parse_url, ) -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Callable from typing import Dict diff --git a/sentry_sdk/integrations/threading.py b/sentry_sdk/integrations/threading.py index f29e5e8797..189731610b 100644 --- a/sentry_sdk/integrations/threading.py +++ b/sentry_sdk/integrations/threading.py @@ -5,11 +5,11 @@ from sentry_sdk import Hub from sentry_sdk._compat import reraise -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.integrations import Integration from sentry_sdk.utils import event_from_exception, capture_internal_exceptions -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import TypeVar from typing import Callable diff --git a/sentry_sdk/integrations/tornado.py b/sentry_sdk/integrations/tornado.py index a64f4f5b11..502aec9800 100644 --- a/sentry_sdk/integrations/tornado.py +++ b/sentry_sdk/integrations/tornado.py @@ -32,9 +32,9 @@ except ImportError: raise DidNotEnable("Tornado not installed") -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Optional from typing import Dict diff --git a/sentry_sdk/integrations/trytond.py b/sentry_sdk/integrations/trytond.py index 062a756993..625c1eeda3 100644 --- a/sentry_sdk/integrations/trytond.py +++ b/sentry_sdk/integrations/trytond.py @@ -2,12 +2,12 @@ import sentry_sdk.utils import sentry_sdk.integrations import sentry_sdk.integrations.wsgi -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from trytond.exceptions import TrytonException # type: ignore from trytond.wsgi import app # type: ignore -if MYPY: +if TYPE_CHECKING: from typing import Any diff --git a/sentry_sdk/integrations/wsgi.py b/sentry_sdk/integrations/wsgi.py index f8b41dc12c..0ab7440afd 100644 --- a/sentry_sdk/integrations/wsgi.py +++ b/sentry_sdk/integrations/wsgi.py @@ -13,9 +13,9 @@ from sentry_sdk.sessions import auto_session_tracking from sentry_sdk.integrations._wsgi_common import _filter_headers -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Callable from typing import Dict from typing import Iterator diff --git a/sentry_sdk/profiler.py b/sentry_sdk/profiler.py index 96ee5f30f9..1695fa34f1 100644 --- a/sentry_sdk/profiler.py +++ b/sentry_sdk/profiler.py @@ -24,7 +24,7 @@ import sentry_sdk from sentry_sdk._compat import PY33, PY311 -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.utils import ( filename_for_module, logger, @@ -32,7 +32,7 @@ set_in_app_in_frames, ) -if MYPY: +if TYPE_CHECKING: from types import FrameType from typing import Any from typing import Callable diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 717f5bb653..b8978c0769 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -3,12 +3,12 @@ from itertools import chain from sentry_sdk._functools import wraps -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.utils import logger, capture_internal_exceptions from sentry_sdk.tracing import Transaction from sentry_sdk.attachments import Attachment -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Dict from typing import Optional diff --git a/sentry_sdk/serializer.py b/sentry_sdk/serializer.py index c1631e47f4..74cbe45b56 100644 --- a/sentry_sdk/serializer.py +++ b/sentry_sdk/serializer.py @@ -24,9 +24,9 @@ binary_sequence_types, ) -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from datetime import timedelta from types import TracebackType diff --git a/sentry_sdk/session.py b/sentry_sdk/session.py index 98a8c72cbb..b0c3d538d0 100644 --- a/sentry_sdk/session.py +++ b/sentry_sdk/session.py @@ -1,10 +1,10 @@ import uuid from datetime import datetime -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.utils import format_timestamp -if MYPY: +if TYPE_CHECKING: from typing import Optional from typing import Union from typing import Any diff --git a/sentry_sdk/sessions.py b/sentry_sdk/sessions.py index 4e4d21b89c..a8f2aedd99 100644 --- a/sentry_sdk/sessions.py +++ b/sentry_sdk/sessions.py @@ -6,10 +6,10 @@ import sentry_sdk from sentry_sdk.envelope import Envelope from sentry_sdk.session import Session -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.utils import format_timestamp -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Callable from typing import Dict diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 4dbc373aa8..efcfc165db 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -6,10 +6,10 @@ import sentry_sdk from sentry_sdk.consts import INSTRUMENTER from sentry_sdk.utils import logger, nanosecond_time -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: import typing from typing import Optional diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index 50d684c388..64155defdf 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -15,7 +15,7 @@ to_string, ) from sentry_sdk._compat import PY2, iteritems -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING if PY2: from collections import Mapping @@ -24,7 +24,7 @@ from collections.abc import Mapping from urllib.parse import quote, unquote -if MYPY: +if TYPE_CHECKING: import typing from typing import Any @@ -398,5 +398,5 @@ def should_propagate_trace(hub, url): # Circular imports from sentry_sdk.tracing import LOW_QUALITY_TRANSACTION_SOURCES -if MYPY: +if TYPE_CHECKING: from sentry_sdk.tracing import Span, Transaction diff --git a/sentry_sdk/transport.py b/sentry_sdk/transport.py index 4937668cc7..9407a4b7be 100644 --- a/sentry_sdk/transport.py +++ b/sentry_sdk/transport.py @@ -13,9 +13,9 @@ from sentry_sdk.worker import BackgroundWorker from sentry_sdk.envelope import Envelope, Item, PayloadRef -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Callable from typing import Dict diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index 48098a885b..6f1a2cb80a 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -39,9 +39,9 @@ import sentry_sdk from sentry_sdk._compat import PY2, PY33, PY37, implements_str, text_type, urlparse -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from types import FrameType, TracebackType from typing import ( Any, @@ -407,7 +407,7 @@ def substituted_because_contains_sensitive_data(cls): ) -if MYPY: +if TYPE_CHECKING: from typing import TypeVar T = TypeVar("T") diff --git a/sentry_sdk/worker.py b/sentry_sdk/worker.py index 310ba3bfb4..ca0ca28d94 100644 --- a/sentry_sdk/worker.py +++ b/sentry_sdk/worker.py @@ -7,9 +7,9 @@ from sentry_sdk.utils import logger from sentry_sdk.consts import DEFAULT_QUEUE_SIZE -from sentry_sdk._types import MYPY +from sentry_sdk._types import TYPE_CHECKING -if MYPY: +if TYPE_CHECKING: from typing import Any from typing import Optional from typing import Callable