How do you use Sentry?
Sentry Saas (sentry.io)
Version
1.12.1
Steps to Reproduce
import sentry_sdk
with sentry_sdk.configure_scope() as scope:
pass
Expected Result
configure_scope should always return ContextManager and should never return None.
Instead of:
-> (ContextManager | None)
should always return:
Actual Result
Pylance complains:
(function) configure_scope(callback: ((Scope) -> None) | None = None) -> (ContextManager | None)
Object of type "None" cannot be used with "with"
Pylance reportOptionalContextManager

Workaround
import sentry_sdk
scope_ctx = sentry_sdk.configure_scope()
if scope_ctx is not None:
with scope_ctx as scope:
pass
or using :=:
import sentry_sdk
if (scope_ctx := sentry_sdk.configure_scope()) is not None:
with scope_ctx as scope:
pass
How do you use Sentry?
Sentry Saas (sentry.io)
Version
1.12.1
Steps to Reproduce
Expected Result
configure_scopeshould always returnContextManagerand should never returnNone.Instead of:
should always return:
Actual Result
Pylance complains:
Pylance reportOptionalContextManager
Workaround
or using
:=: