From 7fcb7cbf0a0f5a30c97cb981a5ca60b57e08b436 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 27 Sep 2019 00:45:30 +0300 Subject: [PATCH] Update type hints and allow InternalEventTypes for @event.on --- maubot/handlers/event.py | 9 +++++---- maubot/matrix.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/maubot/handlers/event.py b/maubot/handlers/event.py index 1c0d72b..f02cc86 100644 --- a/maubot/handlers/event.py +++ b/maubot/handlers/event.py @@ -16,19 +16,20 @@ from typing import Callable, Union, NewType from mautrix.types import EventType -from mautrix.client import EventHandler +from mautrix.client import EventHandler, InternalEventType EventHandlerDecorator = NewType("EventHandlerDecorator", Callable[[EventHandler], EventHandler]) -def on(var: Union[EventType, EventHandler]) -> Union[EventHandlerDecorator, EventHandler]: +def on(var: Union[EventType, InternalEventType, EventHandler] + ) -> Union[EventHandlerDecorator, EventHandler]: def decorator(func: EventHandler) -> EventHandler: func.__mb_event_handler__ = True - if isinstance(var, EventType): + if isinstance(var, (EventType, InternalEventType)): func.__mb_event_type__ = var else: func.__mb_event_type__ = EventType.ALL return func - return decorator if isinstance(var, EventType) else decorator(var) + return decorator if isinstance(var, (EventType, InternalEventType)) else decorator(var) diff --git a/maubot/matrix.py b/maubot/matrix.py index 916875c..a526f8f 100644 --- a/maubot/matrix.py +++ b/maubot/matrix.py @@ -73,7 +73,7 @@ class MaubotMessageEvent(MessageEvent): def mark_read(self) -> Awaitable[None]: return self.client.send_receipt(self.room_id, self.event_id, "m.read") - def react(self, key: str) -> Awaitable[None]: + def react(self, key: str) -> Awaitable[EventID]: return self.client.react(self.room_id, self.event_id, key) def edit(self, content: Union[str, MessageEventContent],