@devries-cameron20 / composio-1 / commits / 2318625ff
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(py): typeguard

jkomyno committed Feb 6, 2026 at 01:32 UTC 2318625fffe3d01ee3e0cd695e7a36645f0f4a43
1 file changed +10 -13
python/composio/core/models/webhook_events.py
+10 -13
@@ -139,14 +139,13 @@ class ConnectionExpiredEvent(te.TypedDict):
139 Emitted when a connected account expires due to authentication refresh failure.
140
141 Example:
142 - >>> from composio.core.models.webhook_events import ConnectionExpiredEvent
142 + >>> from composio.core.models.webhook_events import is_connection_expired_event
143 >>>
144 >>> def handle_webhook(payload: dict) -> None:
145 - ... if payload.get("type") == "composio.connected_account.expired":
146 - ... event: ConnectionExpiredEvent = payload # type: ignore
147 - ... print(f"Connection {event['data']['id']} expired")
148 - ... print(f"Toolkit: {event['data']['toolkit']['slug']}")
149 - ... print(f"User: {event['data']['user_id']}")
145 + ... if is_connection_expired_event(payload):
146 + ... print(f"Connection {payload['data']['id']} expired")
147 + ... print(f"Toolkit: {payload['data']['toolkit']['slug']}")
148 + ... print(f"User: {payload['data']['user_id']}")
149 """
150
151 id: str # Unique message ID (e.g., "msg_847cdfcd-d219-4f18-a6dd-91acd42ca94a")
@@ -160,7 +159,9 @@ class ConnectionExpiredEvent(te.TypedDict):
159 WebhookEvent = t.Union[ConnectionExpiredEvent]
160
161
163 -def is_connection_expired_event(payload: t.Dict[str, t.Any]) -> bool:
162 +def is_connection_expired_event(
163 + payload: t.Dict[str, t.Any],
164 +) -> t.TypeGuard[ConnectionExpiredEvent]:
165 """
166 Check if a webhook payload is a connection expired event.
167
@@ -168,14 +169,10 @@ def is_connection_expired_event(payload: t.Dict[str, t.Any]) -> bool:
169 :return: True if this is a connection expired event
170
171 Example:
171 - >>> from composio.core.models.webhook_events import (
172 - ... is_connection_expired_event,
173 - ... ConnectionExpiredEvent,
174 - ... )
172 + >>> from composio.core.models.webhook_events import is_connection_expired_event
173 >>>
174 >>> if is_connection_expired_event(payload):
177 - ... event: ConnectionExpiredEvent = payload # type: ignore
178 - ... handle_connection_expired(event)
175 + ... handle_connection_expired(payload) # payload is narrowed to ConnectionExpiredEvent
176 """
177 return (
178 isinstance(payload, dict)