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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions sentry_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
if TYPE_CHECKING:
from sentry_sdk._types import Event, Hint
else:
from typing import Any

Check warning on line 16 in sentry_sdk/types.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/types.py#L16

Added line #L16 was not covered by tests

# The lines below allow the types to be imported from outside `if TYPE_CHECKING`
# guards. The types in this module are only intended to be used for type hints.
Event = None
Hint = None
Event = Any
Hint = Any

Check warning on line 21 in sentry_sdk/types.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/types.py#L20-L21

Added lines #L20 - L21 were not covered by tests

__all__ = ("Event", "Hint")
17 changes: 17 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from sentry_sdk.types import Event, Hint


def test_event_or_none_runtime():
"""
Ensures that the `Event` type's runtime value supports the `|` operation with `None`.
This test is needed to ensure that using an `Event | None` type hint (e.g. for
`before_send`'s return value) does not raise a TypeError at runtime.
"""
Event | None


def test_hint_or_none_runtime():
"""
Analogue to `test_event_or_none_runtime`, but for the `Hint` type.
"""
Hint | None