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 all commits
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

# 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

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

import pytest
from sentry_sdk.types import Event, Hint


@pytest.mark.skipif(
sys.version_info < (3, 10),
reason="Type hinting with `|` is available in Python 3.10+",
)
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


@pytest.mark.skipif(
sys.version_info < (3, 10),
reason="Type hinting with `|` is available in Python 3.10+",
)
def test_hint_or_none_runtime():
"""
Analogue to `test_event_or_none_runtime`, but for the `Hint` type.
"""
Hint | None