diff --git a/src/lvmopstools/slack.py b/src/lvmopstools/slack.py index c9bf10b..762a4d6 100644 --- a/src/lvmopstools/slack.py +++ b/src/lvmopstools/slack.py @@ -18,6 +18,13 @@ from lvmopstools import config +try: + from slack_sdk.errors import SlackApiError + from slack_sdk.web.async_client import AsyncWebClient +except ImportError: + AsyncWebClient = None + SlackApiError = None + __all__ = ["post_message", "get_user_id", "get_user_list"] @@ -29,9 +36,7 @@ def get_api_client(token: str | None = None): """Gets a Slack API client.""" - try: - from slack_sdk.web.async_client import AsyncWebClient - except ImportError: + if AsyncWebClient is None: raise ImportError( "slack-sdk is not installed. Install the slack or all extras." ) @@ -96,11 +101,6 @@ async def post_message( """ - try: - from slack_sdk.errors import SlackApiError - except ImportError: - SlackApiError = None - if text is None and blocks is None: raise ValueError("Must specify either text or blocks.") @@ -138,11 +138,6 @@ async def get_user_list(): """ - try: - from slack_sdk.errors import SlackApiError - except ImportError: - SlackApiError = None - client = get_api_client() assert SlackApiError is not None