-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
fd8a9b2
commit 336f7d5
Showing
2 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
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 |