From 7772cf394fd8ddc211367bd1867b90454ef221c1 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Fri, 23 Jun 2023 11:28:38 +0300 Subject: [PATCH] dispatcher: support additional arguments --- src/mdis/dispatcher.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/mdis/dispatcher.py b/src/mdis/dispatcher.py index c956e0c..63b1ebb 100644 --- a/src/mdis/dispatcher.py +++ b/src/mdis/dispatcher.py @@ -33,8 +33,11 @@ class Hook(object): def __call__(self, call): class ConcreteHook(Hook): - def __call__(self, dispatcher, node, *args, **kwargs): - return call(dispatcher, node, *args, **kwargs) + def __call__(self, dispatcher, node, *arguments): + try: + return call(dispatcher, node, *arguments) + except TypeError: + return call(dispatcher, node) return ConcreteHook(*tuple(self)) @@ -81,15 +84,15 @@ class DispatcherMeta(type): class Dispatcher(metaclass=DispatcherMeta): - def __call__(self, node, *args, **kwargs): + def __call__(self, node, *arguments): for typeid in node.__class__.__mro__: hook = self.__class__.dispatch(typeid=typeid) if hook is not None: break if hook is None: hook = self.__class__.dispatch() - return hook(self, node, *args, **kwargs) + return hook(self, node, *arguments) @Hook(object) - def dispatch_object(self, node, *args, **kwargs): + def dispatch_object(self, node, *arguments): raise NotImplementedError() -- 2.30.2