From c5a8652df545a94a7463974530cd4ef9bbe882b3 Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Mon, 1 Jun 2026 09:36:43 +0300 Subject: [PATCH] fix: tighten Sentry idiom and typing micro-issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LOW-1: wrap_before_send_callbacks used `if not callback:` to skip None entries in *callbacks. Callables are always truthy unless they define __bool__, so the truthiness check is semantically wrong even if it happens to work. Use `if callback is None:` to match the intent. LOW-2: SentryConfig.sentry_before_send was annotated `Callable[[Any, Any], Any | None] | None`. The inner `Any | None` collapses to `Any`, so the annotation reduces to `Callable[..., Any] | None` — the union adds nothing. Use the proper `sentry_types.EventProcessor | None` instead (already imported under TYPE_CHECKING in the same file). No behavior change. Closes LOW-1 and LOW-2 from the audit. --- lite_bootstrap/instruments/sentry_instrument.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lite_bootstrap/instruments/sentry_instrument.py b/lite_bootstrap/instruments/sentry_instrument.py index c109cb6..8ef1247 100644 --- a/lite_bootstrap/instruments/sentry_instrument.py +++ b/lite_bootstrap/instruments/sentry_instrument.py @@ -33,7 +33,7 @@ class SentryConfig(BaseConfig): sentry_additional_params: dict[str, typing.Any] = dataclasses.field(default_factory=dict) sentry_tags: dict[str, str] | None = None sentry_default_integrations: bool = True - sentry_before_send: typing.Callable[[typing.Any, typing.Any], typing.Any | None] | None = None + sentry_before_send: "sentry_types.EventProcessor | None" = None def enrich_sentry_event_from_structlog_log( @@ -78,7 +78,7 @@ def run_before_send( event: "sentry_types.Event", hint: "sentry_types.Hint" ) -> typing.Optional["sentry_types.Event"]: for callback in callbacks: - if not callback: + if callback is None: continue temp_event = callback(event, hint)