diff --git a/slack_bolt/app/async_app.py b/slack_bolt/app/async_app.py index 819ab1879..8f66e3ba3 100644 --- a/slack_bolt/app/async_app.py +++ b/slack_bolt/app/async_app.py @@ -25,7 +25,7 @@ AsyncMessageListenerMatches, ) from slack_bolt.oauth.async_internals import select_consistent_installation_store -from slack_bolt.util.utils import get_name_for_callable, is_coroutine_function +from slack_bolt.util.utils import get_name_for_callable, is_callable_coroutine from slack_bolt.workflows.step.async_step import ( AsyncWorkflowStep, AsyncWorkflowStepBuilder, @@ -786,7 +786,7 @@ async def custom_error_handler(error, body, logger): func: The function that is supposed to be executed when getting an unhandled error in Bolt app. """ - if not is_coroutine_function(func): + if not is_callable_coroutine(func): name = get_name_for_callable(func) raise BoltError(error_listener_function_must_be_coro_func(name)) self._async_listener_runner.listener_error_handler = AsyncCustomListenerErrorHandler( @@ -1418,7 +1418,7 @@ def _register_listener( value_to_return = functions[0] for func in functions: - if not is_coroutine_function(func): + if not is_callable_coroutine(func): name = get_name_for_callable(func) raise BoltError(error_listener_function_must_be_coro_func(name)) @@ -1430,7 +1430,7 @@ def _register_listener( for m in middleware or []: if isinstance(m, AsyncMiddleware): listener_middleware.append(m) - elif callable(m) and is_coroutine_function(m): + elif callable(m) and is_callable_coroutine(m): listener_middleware.append(AsyncCustomMiddleware(app_name=self.name, func=m, base_logger=self._base_logger)) else: raise ValueError(error_unexpected_listener_middleware(type(m))) diff --git a/slack_bolt/middleware/async_custom_middleware.py b/slack_bolt/middleware/async_custom_middleware.py index 77bfb2687..18856a3b2 100644 --- a/slack_bolt/middleware/async_custom_middleware.py +++ b/slack_bolt/middleware/async_custom_middleware.py @@ -6,7 +6,7 @@ from slack_bolt.request.async_request import AsyncBoltRequest from slack_bolt.response import BoltResponse from .async_middleware import AsyncMiddleware -from slack_bolt.util.utils import get_name_for_callable, get_arg_names_of_callable, is_coroutine_function +from slack_bolt.util.utils import get_name_for_callable, get_arg_names_of_callable, is_callable_coroutine class AsyncCustomMiddleware(AsyncMiddleware): @@ -23,7 +23,7 @@ def __init__( base_logger: Optional[Logger] = None, ): self.app_name = app_name - if is_coroutine_function(func): + if is_callable_coroutine(func): self.func = func else: raise ValueError("Async middleware function must be an async function") diff --git a/slack_bolt/util/utils.py b/slack_bolt/util/utils.py index a5bcdbe5f..738b6bf03 100644 --- a/slack_bolt/util/utils.py +++ b/slack_bolt/util/utils.py @@ -90,7 +90,7 @@ def get_arg_names_of_callable(func: Callable) -> List[str]: return inspect.getfullargspec(inspect.unwrap(func)).args -def is_coroutine_function(func: Optional[Any]) -> bool: +def is_callable_coroutine(func: Optional[Any]) -> bool: return func is not None and ( inspect.iscoroutinefunction(func) or (hasattr(func, "__call__") and inspect.iscoroutinefunction(func.__call__)) )