Skip to content

Commit

Permalink
Better handling of missing imports in slack module
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Dec 23, 2024
1 parent b89ea72 commit 59296bf
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/lvmopstools/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]


Expand All @@ -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."
)
Expand Down Expand Up @@ -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.")

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 59296bf

Please sign in to comment.