Coverage for formkit_ninja / notifications.py: 0.00%
20 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-03 09:21 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-03 09:21 +0000
1"""
2Notification helpers for optional integrations like Sentry.
3"""
5from __future__ import annotations
7import importlib
8from importlib.util import find_spec
9from typing import Protocol
12class Notifier(Protocol):
13 """Protocol for sending notifications."""
15 def notify(self, message: str) -> None:
16 """Send a message to the notification backend."""
19class NullNotifier:
20 """No-op notifier for when integrations are unavailable."""
22 def notify(self, message: str) -> None:
23 return None
26class SentryNotifier:
27 """Notifier that sends messages to sentry_sdk if available."""
29 def __init__(self, sentry_sdk: object) -> None:
30 self._sentry_sdk = sentry_sdk
32 def notify(self, message: str) -> None:
33 if hasattr(self._sentry_sdk, "capture_message"):
34 self._sentry_sdk.capture_message(message)
37def get_default_notifier() -> Notifier:
38 """Return the best available notifier for this runtime."""
39 if find_spec("sentry_sdk"):
40 sentry_sdk = importlib.import_module("sentry_sdk")
41 return SentryNotifier(sentry_sdk)
42 return NullNotifier()