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

Conversation

untitaker
Copy link
Member

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.

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:
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

@antonpirker antonpirker merged commit 1e3e109 into master Mar 3, 2023
@antonpirker antonpirker deleted the fix/mypy-typechecking branch March 3, 2023 06:42
@antonpirker antonpirker self-assigned this Mar 3, 2023
Comment on lines 1 to +4
try:
from typing import TYPE_CHECKING as MYPY
from typing import TYPE_CHECKING as TYPE_CHECKING
except ImportError:
MYPY = False
TYPE_CHECKING = False
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants