fix: Rename MYPY to TYPE_CHECKING#1934
Merged
Merged
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.
sl0thentr0py
reviewed
Mar 1, 2023
| from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration | ||
|
|
||
| if MYPY: | ||
| if TYPE_CHECKING: |
Member
There was a problem hiding this comment.
should we still expose MYPY as an alias just in case someone's importing it currently?
Member
Author
There was a problem hiding this comment.
oh.... yeah. probably. they shouldn't do that, right?
Member
There was a problem hiding this comment.
shouldn't.. but I would remove it in a major just to be safe
sl0thentr0py
approved these changes
Mar 1, 2023
aqeelat
reviewed
Mar 23, 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 |
There was a problem hiding this comment.
two questions:
- why the try-catch?
- why
from x import y as y?
Member
Author
There was a problem hiding this comment.
- because the SDK supports Python 2, so
typingmight 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
This was referenced Oct 27, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.