From b779db58605ac1aade6e8c8583ff418281bb8290 Mon Sep 17 00:00:00 2001 From: Melvin Carvalho Date: Sun, 18 Oct 2026 19:06:14 +0200 Subject: [PATCH] Python SDKs: register the mautrix handler with add_event_handler so the sample type-checks --- docs/sdks/matrix-python-sdk.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/sdks/matrix-python-sdk.md b/docs/sdks/matrix-python-sdk.md index bf5947e..d48621a 100644 --- a/docs/sdks/matrix-python-sdk.md +++ b/docs/sdks/matrix-python-sdk.md @@ -125,7 +125,7 @@ mautrix-python is the library under [maubot](../bots/maubot). Most mautrix bridg ### A minimal client -Checked against mautrix 0.21.1 by constructing the client and registering the handler, without network access. Create the `Client` inside a running event loop. +Checked against mautrix 0.21.1 with pyright (no errors), and by constructing the client and registering the handler without network access. Create the `Client` inside a running event loop. The `@client.on(...)` decorator also works at runtime, but its type hints make pyright report an error, so this sample uses `add_event_handler`. ```python import asyncio @@ -144,11 +144,12 @@ async def main() -> None: client.ignore_initial_sync = True # don't replay history on startup client.ignore_first_sync = True - @client.on(EventType.ROOM_MESSAGE) async def handler(evt: MessageEvent) -> None: if evt.sender != client.mxid and evt.content.body == "!ping": await client.send_notice(evt.room_id, "pong") + client.add_event_handler(EventType.ROOM_MESSAGE, handler) + await client.start(None) # runs until stopped