getsentry / getsentry/sentry-python

Don't export `Any` instead of instantiable types

未關閉
#4,656 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
Component: Typing Errors Improvement Python
主要語言
Python
星號
2.2k
分支
669
平均合併
1 天 1 小時
30 天內合併 PR
213

描述

`sentry_sdk/types.py` exports types for hinting, but some of the types it exports in type-checking mode can be instantiated. This creates a dangerous mismatch between the type-checking and runtime API where i.e, `Event()` will appear valid due to being a `TypedDict`, but will raise an `Any type cannot be instantiated` error at runtime.

I don't think there's an easy solution for hinting the type checker about hint-only types, but also I'm not sure why the `_types.py` code is behind `if TYPE_CHECKING:`. My recommendation would either be:
* Just remove the `if TYPE_CHECKING:` or,
* Export instantiable substitutes versions of the instantiable types (maybe just TypedDict types but not sure)

https://github.com/getsentry/sentry-python/blob/84adbb74e27b7716cbaaddbb299a44fe3fbcd6a6/sentry_sdk/types.py#L28-L37

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。