Skip to content

Commit

Permalink
ref(types): Replace custom TYPE_CHECKING with stdlib typing.TYPE_CHEC…
Browse files Browse the repository at this point in the history
…KING (#3447)

---------

Co-authored-by: Ivana Kellyer <ivana.kellyer@sentry.io>
  • Loading branch information
dev-satoshi and sentrivana authored Aug 27, 2024
1 parent 306c34e commit 4b361c5
Show file tree
Hide file tree
Showing 115 changed files with 192 additions and 142 deletions.
3 changes: 2 additions & 1 deletion scripts/init_serverless_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import re

import sentry_sdk
from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any

Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/_compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys

from sentry_sdk._types import TYPE_CHECKING
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
from collections import deque
from time import time

from sentry_sdk._types import TYPE_CHECKING
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
Expand Down
5 changes: 1 addition & 4 deletions sentry_sdk/_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
try:
from typing import TYPE_CHECKING
except ImportError:
TYPE_CHECKING = False
from typing import TYPE_CHECKING


# Re-exported for compat, since code out there in the wild might use this variable.
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/_werkzeug.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
SUCH DAMAGE.
"""

from sentry_sdk._types import TYPE_CHECKING
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Dict
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/ai/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from sentry_sdk import start_span
from sentry_sdk.tracing import Span
from sentry_sdk.utils import ContextVar
from sentry_sdk._types import TYPE_CHECKING

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Optional, Callable, Any
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/ai/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sentry_sdk._types import TYPE_CHECKING
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
Expand Down
3 changes: 1 addition & 2 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from sentry_sdk.tracing import NoOpSpan, Transaction, trace
from sentry_sdk.crons import monitor


from sentry_sdk._types import TYPE_CHECKING
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Mapping
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/attachments.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import mimetypes

from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.envelope import Item, PayloadRef

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Optional, Union, Callable

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from sentry_sdk.monitor import Monitor
from sentry_sdk.spotlight import setup_spotlight

from sentry_sdk._types import TYPE_CHECKING
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
Expand Down Expand Up @@ -881,7 +881,7 @@ def __exit__(self, exc_type, exc_value, tb):
self.close()


from sentry_sdk._types import TYPE_CHECKING
from typing import TYPE_CHECKING

if TYPE_CHECKING:
# Make mypy, PyCharm and other static analyzers think `get_options` is a
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import itertools

from enum import Enum
from sentry_sdk._types import TYPE_CHECKING
from typing import TYPE_CHECKING

# up top to prevent circular import due to integration import
DEFAULT_MAX_VALUE_LENGTH = 1024
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/crons/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import uuid

import sentry_sdk
from sentry_sdk._types import TYPE_CHECKING

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Optional
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/crons/decorator.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from functools import wraps
from inspect import iscoroutinefunction

from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.crons import capture_checkin
from sentry_sdk.crons.consts import MonitorStatus
from sentry_sdk.utils import now

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Awaitable, Callable
from types import TracebackType
Expand Down
3 changes: 1 addition & 2 deletions sentry_sdk/db/explain_plan/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from datetime import datetime, timedelta, timezone

from sentry_sdk.consts import TYPE_CHECKING
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/db/explain_plan/django.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sentry_sdk.consts import TYPE_CHECKING
from typing import TYPE_CHECKING

from sentry_sdk.db.explain_plan import cache_statement, should_run_explain_plan

if TYPE_CHECKING:
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/db/explain_plan/sqlalchemy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sentry_sdk.consts import TYPE_CHECKING
from typing import TYPE_CHECKING

from sentry_sdk.db.explain_plan import cache_statement, should_run_explain_plan
from sentry_sdk.integrations import DidNotEnable

Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import json
import mimetypes

from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.session import Session
from sentry_sdk.utils import json_dumps, capture_internal_exceptions

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
from typing import Optional
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
ContextVar,
)

from sentry_sdk._types import TYPE_CHECKING
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from abc import ABC, abstractmethod
from threading import Lock

from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.utils import logger

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Sequence
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/_asgi_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.integrations._wsgi_common import _filter_headers
from sentry_sdk._types import TYPE_CHECKING

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/_wsgi_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import sentry_sdk
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.utils import AnnotatedValue, logger
from sentry_sdk._types import TYPE_CHECKING

try:
from django.http.request import RawPostDataException
except ImportError:
RawPostDataException = None

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
except ImportError:
raise DidNotEnable("AIOHTTP not installed")

from sentry_sdk._types import TYPE_CHECKING
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from aiohttp.web_request import Request
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/argv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sentry_sdk.integrations import Integration
from sentry_sdk.scope import add_global_event_processor

from sentry_sdk._types import TYPE_CHECKING
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Optional
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/ariadne.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
event_from_exception,
package_version,
)
from sentry_sdk._types import TYPE_CHECKING

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

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any, Dict, List, Optional
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/arq.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys

import sentry_sdk
from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.consts import OP, SPANSTATUS
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.integrations.logging import ignore_logger
Expand All @@ -24,6 +23,8 @@
except ImportError:
raise DidNotEnable("Arq is not installed")

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any, Dict, Optional, Union

Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from functools import partial

import sentry_sdk
from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.api import continue_trace
from sentry_sdk.consts import OP

Expand All @@ -37,6 +36,8 @@
)
from sentry_sdk.tracing import Transaction

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
from typing import Callable
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sentry_sdk
from sentry_sdk.consts import OP
from sentry_sdk.integrations import Integration, DidNotEnable
from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.utils import event_from_exception, reraise

try:
Expand All @@ -12,6 +11,7 @@
except ImportError:
raise DidNotEnable("asyncio not available")

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/atexit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from sentry_sdk.utils import logger
from sentry_sdk.integrations import Integration
from sentry_sdk.utils import ensure_integration_enabled
from sentry_sdk._types import TYPE_CHECKING

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
)
from sentry_sdk.integrations import Integration
from sentry_sdk.integrations._wsgi_common import _filter_headers
from sentry_sdk._types import TYPE_CHECKING

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
event_from_exception,
reraise,
)
from sentry_sdk._types import TYPE_CHECKING

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import Integration, DidNotEnable
from sentry_sdk.tracing import Span

from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
parse_url,
parse_version,
)

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
from typing import Dict
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from sentry_sdk.integrations import Integration, DidNotEnable
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
from sentry_sdk.integrations._wsgi_common import RequestExtractor
from sentry_sdk._types import TYPE_CHECKING

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from sentry_sdk.integrations.wsgi import _ScopedResponse
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch
from sentry_sdk.integrations.logging import ignore_logger
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, TRANSACTION_SOURCE_TASK
from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.tracing_utils import Baggage
from sentry_sdk.utils import (
capture_internal_exceptions,
Expand All @@ -24,6 +23,8 @@
reraise,
)

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any
from typing import Callable
Expand Down
3 changes: 2 additions & 1 deletion sentry_sdk/integrations/celery/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
_get_humanized_interval,
_now_seconds_since_epoch,
)
from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.utils import (
logger,
match_regex_list,
)

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Callable
from typing import Any, Optional, TypeVar, Union
Expand Down
4 changes: 1 addition & 3 deletions sentry_sdk/integrations/celery/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import time
from typing import cast

from sentry_sdk._types import TYPE_CHECKING
from typing import TYPE_CHECKING, cast

if TYPE_CHECKING:
from typing import Any, Tuple
Expand Down
Loading

0 comments on commit 4b361c5

Please sign in to comment.