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(types): Fixed Event | None runtime TypeError #2928

Merged
merged 2 commits into from
Apr 2, 2024

Conversation

szokeasaurusrex
Copy link
Member

Change Event's runtime value to typing.Any, since the previous value of None caused the expression Event | None to result in a TypeError at runtime, even when the Event | None expression was used as a type hint. Also, add a test to make sure we don't reintroduce this bug.

Fixes GH-2926

@szokeasaurusrex szokeasaurusrex enabled auto-merge (squash) April 2, 2024 10:19
@antonpirker
Copy link
Member

One question: Why are we not importing the types from _types no matter what TYPE_CHECKING is?

@szokeasaurusrex
Copy link
Member Author

One question: Why are we not importing the types from _types no matter what TYPE_CHECKING is?

All the types are defined within an if TYPE_CHECKING block. So, the types only exist in TYPE_CHECKING environments. Attempting the import at runtime results in an ImportError:

>>> from sentry_sdk._types import Event
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Event' from 'sentry_sdk._types' (/Users/dszoke/Development/SDK/sentry-python/sentry_sdk/_types.py)

@szokeasaurusrex szokeasaurusrex merged commit 336f7d5 into master Apr 2, 2024
123 of 124 checks passed
@szokeasaurusrex szokeasaurusrex deleted the szokeasaurusrex/fix-runtime-types branch April 2, 2024 11:00
szokeasaurusrex added a commit to getsentry/sentry that referenced this pull request Apr 3, 2024
`sentry-sdk` version `1.44.1` includes an important
[bugfix](getsentry/sentry-python#2928).
shellmayr pushed a commit to getsentry/sentry that referenced this pull request Apr 10, 2024
`sentry-sdk` version `1.44.1` includes an important
[bugfix](getsentry/sentry-python#2928).
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.

Set Event to something other than None at runtime
2 participants