Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: inspect.isfunction -> inspect.isroutine #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions mediatr/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down
12 changes: 6 additions & 6 deletions mediatr/mediator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down