From 381cedda58a947ea642f0d2cb9ad6658777a07e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=83=D1=80=D0=BC=D0=B0=D1=88=20=D0=90=D0=BF=D0=B0?= =?UTF-8?q?=D0=B5=D0=B2?= Date: Wed, 2 Mar 2022 10:09:46 +0600 Subject: [PATCH] Fix: inspect.isfunction -> inspect.isroutine --- mediatr/exceptions.py | 8 ++++---- mediatr/mediator.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mediatr/exceptions.py b/mediatr/exceptions.py index 1588b34..4743efb 100644 --- a/mediatr/exceptions.py +++ b/mediatr/exceptions.py @@ -12,14 +12,14 @@ def raise_if_request_none(request): def raise_if_handler_is_invalid(handler): - isfunc = inspect.isfunction(handler) + isfunc = inspect.isroutine(handler) func = None if isfunc: func = handler else: if hasattr(handler, 'handle'): - if inspect.isfunction(handler.handle): + if inspect.isroutine(handler.handle): func = handler.handle elif inspect.ismethod(handler.handle): func = handler.__class__.handle @@ -33,9 +33,9 @@ def raise_if_handler_is_invalid(handler): def raise_if_behavior_is_invalid(behavior): - isfunc = inspect.isfunction(behavior) + isfunc = inspect.isroutine(behavior) func = behavior if isfunc else (behavior.handle if hasattr(behavior, 'handle') else None) - if not func or not inspect.isfunction(func): + if not func or not inspect.isroutine(func): raise InvalidHandlerError(func) sign = inspect.signature(func) params_l = len(sign.parameters.keys()) diff --git a/mediatr/mediator.py b/mediatr/mediator.py index e58bcd1..993f379 100644 --- a/mediatr/mediator.py +++ b/mediatr/mediator.py @@ -15,14 +15,14 @@ def default_handler_class_manager(HandlerCls:type,is_behavior:bool=False): return HandlerCls() def extract_request_type(handler, is_behavior=False) -> type: - isfunc = inspect.isfunction(handler) + isfunc = inspect.isroutine(handler) func = None if isfunc: func = handler else: if hasattr(handler, 'handle'): - if inspect.isfunction(handler.handle): + if inspect.isroutine(handler.handle): func = handler.handle elif inspect.ismethod(handler.handle): func = handler.__class__.handle @@ -83,7 +83,7 @@ async def send_async(self: Union["Mediator",GenericQuery[TResponse]], request: O raise_if_handler_not_found(handler,request) handler_func = None handler_obj = None - if inspect.isfunction(handler): + if inspect.isroutine(handler): handler_func = handler else: handler_obj = self1.handler_class_manager(handler) @@ -95,7 +95,7 @@ async def send_async(self: Union["Mediator",GenericQuery[TResponse]], request: O async def start_func(i:int): beh = behaviors[i] beh_func = None - if inspect.isfunction(beh): + if inspect.isroutine(beh): beh_func = beh else: beh_obj = self1.handler_class_manager(beh, True) @@ -130,7 +130,7 @@ def send(self: Union["Mediator", GenericQuery[TResponse]], request: Optional[Gen raise_if_handler_not_found(handler,request) handler_func = None handler_obj = None - if inspect.isfunction(handler): + if inspect.isroutine(handler): handler_func = handler else: handler_obj = self1.handler_class_manager(handler) @@ -141,7 +141,7 @@ def send(self: Union["Mediator", GenericQuery[TResponse]], request: Optional[Gen def start_func(i:int): beh = behaviors[i] beh_func = None - if inspect.isfunction(beh): + if inspect.isroutine(beh): beh_func = beh else: beh_obj = self1.handler_class_manager(beh, True)