Skip to content

fix: Rename MYPY to TYPE_CHECKING#1934

Merged
antonpirker merged 4 commits into
masterfrom
fix/mypy-typechecking
Mar 3, 2023
Merged

fix: Rename MYPY to TYPE_CHECKING#1934
antonpirker merged 4 commits into
masterfrom
fix/mypy-typechecking

Conversation

@untitaker
Copy link
Copy Markdown
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.
@untitaker untitaker requested a review from sl0thentr0py March 1, 2023 15:53
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration

if MYPY:
if TYPE_CHECKING:
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 thread sentry_sdk/_types.py
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
Copy Markdown

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
Copy Markdown
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.

4 participants