-
Notifications
You must be signed in to change notification settings - Fork 509
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
Do not export types behind TYPE_CHECKING #2909
Comments
alternatively #2829 (comment) -- though it would be ideal to have the actual type definitions be real and available |
Unfortunately, this would not be possible in the SDK, since we have to maintain compatibility with legacy Python versions at runtime. Many of our types, including the
Likewise, we cannot implement the suggestion in #2829 (comment), because I think the best solution is to set the types to |
Set types in sentry_sdk.types to None at runtime. This allows the types to be imported from outside if TYPE_CHECKING guards. Fixes GH-2909 Co-authored-by: Anton Pirker <[email protected]> Co-authored-by: anthony sottile <[email protected]>
@szokeasaurusrex If you can't use from typing import TYPE_CHECKING, Dict, Any
if TYPE_CHECKING:
from sentry_sdk._types import Event, Hint # noqa: F401
else:
Event = Dict[str, Any]
Hint = Dict[str, Any] ? |
@HansAarneLiblik There is no use for Setting these to a different type at runtime is somewhat confusing, because Is there a specific use case that setting these types to |
Nope, just was a question on the thought process 🙂 |
@HansAarneLiblik alright, thanks for the clarification! I understand that this solution is perhaps less than ideal, but I think it is the best we can do in order to enable detailed type hints while also maintaining runtime compatibility with legacy Python versions which lack support for many typing features. |
@szokeasaurusrex Actually I may have an issue with this. We have typed def before_send_sentry(event: Event, hint: dict[str, Any]) -> Event | None:
exc_info = hint.get("exc_info")
if exc_info and "FailTask" in str(exc_info[0]):
print("FailTask exception, NOT SENDING TO SENTRY")
return None
return event Now, runtime, TypeError: unsupported operand type(s) for |: 'NoneType' and 'NoneType' Perhaps there is another way to handle |
Hi @HansAarneLiblik, thank you for bringing this problem to our attention! This seems like a pretty serious bug, so we will need to assign |
Problem Statement
Currently
Event
and friends are exported behind theTYPE_CHECKING
conditional. Meaning imports of these types must also be behind these conditionals.cc @asottile-sentry
Solution Brainstorm
Export without the
TYPE_CHECKING
conditionalThe text was updated successfully, but these errors were encountered: