Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Rename MYPY to TYPE_CHECKING #1934

Merged
merged 4 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/init_serverless_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we still expose MYPY as an alias just in case someone's importing it currently?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh.... yeah. probably. they shouldn't do that, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't.. but I would remove it in a major just to be safe

from typing import Any


Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/_compat.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 3 additions & 3 deletions sentry_sdk/_types.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
try:
from typing import TYPE_CHECKING as MYPY
from typing import TYPE_CHECKING as TYPE_CHECKING
except ImportError:
MYPY = False
TYPE_CHECKING = False
Comment on lines 1 to +4
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two questions:

  1. why the try-catch?
  2. why from x import y as y?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. because the SDK supports Python 2, so typing might not exist. See https://unterwaditzer.net/2019/mypy-and-python2.html
  2. because I did search-and-replace on the entire codebase and didn't check the output carefully enough



if MYPY:
if TYPE_CHECKING:
from types import TracebackType
from typing import Any
from typing import Callable
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/attachments.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
8 changes: 4 additions & 4 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -512,9 +512,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.
#
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions sentry_sdk/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
#
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/_wsgi_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/argv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/arq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -15,7 +15,7 @@
raise DidNotEnable("asyncio not available")


if MYPY:
if TYPE_CHECKING:
from typing import Any

from sentry_sdk._types import ExcInfo
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/atexit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/chalice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/cloud_resource_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/dedupe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading