From 262a6b5f1363358be5ed1ff051625429dae9cfbe Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Tue, 20 Jun 2023 21:16:50 +0300 Subject: [PATCH] dispatcher: support args and kwargs --- src/mdis/dispatcher.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mdis/dispatcher.py b/src/mdis/dispatcher.py index a23cd02..7add027 100644 --- a/src/mdis/dispatcher.py +++ b/src/mdis/dispatcher.py @@ -33,8 +33,9 @@ class Hook(object): def __call__(self, call): class ConcreteHook(Hook): - def __call__(self, dispatcher, instance): - return call(self=dispatcher, instance=instance) + def __call__(self, dispatcher, instance, *args, **kwargs): + return call(self=dispatcher, instance=instance, + *args, **kwargs) return ConcreteHook(*tuple(self)) @@ -81,15 +82,15 @@ class DispatcherMeta(type): class Dispatcher(metaclass=DispatcherMeta): - def __call__(self, instance): + def __call__(self, instance, *args, **kwargs): for typeid in instance.__class__.__mro__: hook = self.__class__.dispatch(typeid=typeid) if hook is not None: break if hook is None: hook = self.__class__.dispatch() - return hook(dispatcher=self, instance=instance) + return hook(dispatcher=self, instance=instance, *args, **kwargs) @Hook(object) - def dispatch_object(self, instance): + def dispatch_object(self, instance, *args, **kwargs): raise NotImplementedError() -- 2.30.2