-
Notifications
You must be signed in to change notification settings - Fork 517
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
Conversation
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.
from sentry_sdk.utils import Dsn | ||
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration | ||
|
||
if MYPY: | ||
if TYPE_CHECKING: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
try: | ||
from typing import TYPE_CHECKING as MYPY | ||
from typing import TYPE_CHECKING as TYPE_CHECKING | ||
except ImportError: | ||
MYPY = False | ||
TYPE_CHECKING = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two questions:
- why the try-catch?
- why
from x import y as y
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- because the SDK supports Python 2, so
typing
might not exist. See https://unterwaditzer.net/2019/mypy-and-python2.html - because I did search-and-replace on the entire codebase and didn't check the output carefully enough
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.