Skip to content

Commit

Permalink
ref: fix typing for some slack helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile-sentry committed Jan 17, 2025
1 parent 22d561f commit d9a1b8c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ module = [
"sentry.integrations.slack.integration",
"sentry.integrations.slack.message_builder.notifications.issues",
"sentry.integrations.slack.notifications",
"sentry.integrations.slack.unfurl.discover",
"sentry.integrations.slack.utils.channel",
"sentry.integrations.slack.utils.users",
"sentry.integrations.slack.webhooks.command",
"sentry.integrations.slack.webhooks.event",
"sentry.integrations.utils.commit_context",
Expand Down
6 changes: 5 additions & 1 deletion src/sentry/integrations/slack/unfurl/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ def _unfurl_discover(
)
params.setlist("name", params.getlist("name") or to_list(saved_query.get("name")))

saved_query_dataset = dataset_map.get(saved_query.get("queryDataset"))
query_dataset = saved_query.get("queryDataset")
if query_dataset is not None:
saved_query_dataset = dataset_map.get(query_dataset)
else:
saved_query_dataset = None
params.setlist(
"dataset",
params.getlist("dataset")
Expand Down
10 changes: 5 additions & 5 deletions src/sentry/integrations/slack/utils/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_channel_id(
return get_channel_id_with_timeout(integration, channel_name, timeout)


def validate_channel_id(name: str, integration_id: int | None, input_channel_id: str) -> None:
def validate_channel_id(name: str, integration_id: int, input_channel_id: str) -> None:
"""
In the case that the user is creating an alert via the API and providing the channel ID and name
themselves, we want to make sure both values are correct.
Expand Down Expand Up @@ -180,7 +180,7 @@ def get_channel_id_with_timeout(


def check_user_with_timeout(
integration: Integration, name: str, time_to_quit: int
integration: Integration | RpcIntegration, name: str, time_to_quit: float
) -> SlackChannelIdData:
"""
If the channel is not found, we check if the name is a user.
Expand Down Expand Up @@ -297,15 +297,15 @@ def check_for_channel(

try:
client.chat_deleteScheduledMessage(
channel=msg_response.get("channel"),
scheduled_message_id=msg_response.get("scheduled_message_id"),
channel=msg_response["channel"],
scheduled_message_id=msg_response["scheduled_message_id"],
)
metrics.incr(
SLACK_UTILS_CHANNEL_SUCCESS_DATADOG_METRIC,
sample_rate=1.0,
tags={"type": "chat_deleteScheduledMessage"},
)
return msg_response.get("channel")
return msg_response["channel"]
except SlackApiError as e:
metrics.incr(
SLACK_UTILS_CHANNEL_FAILURE_DATADOG_METRIC,
Expand Down
12 changes: 5 additions & 7 deletions src/sentry/integrations/slack/utils/users.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import logging
from collections.abc import Iterable, Mapping, MutableMapping
from collections.abc import Generator, Iterable, Mapping, MutableMapping
from dataclasses import dataclass
from typing import Any

Expand Down Expand Up @@ -32,7 +32,7 @@ class SlackUserData:
slack_id: str


def format_slack_info_by_email(users: dict[str, Any]) -> dict[str, SlackUserData]:
def format_slack_info_by_email(users: list[dict[str, Any]]) -> dict[str, SlackUserData]:
return {
member["profile"]["email"]: SlackUserData(
email=member["profile"]["email"], team_id=member["team_id"], slack_id=member["id"]
Expand All @@ -43,7 +43,7 @@ def format_slack_info_by_email(users: dict[str, Any]) -> dict[str, SlackUserData


def format_slack_data_by_user(
emails_by_user: Mapping[User, Iterable[str]], users: dict[str, Any]
emails_by_user: Mapping[User, Iterable[str]], users: list[dict[str, Any]]
) -> Mapping[User, SlackUserData]:
slack_info_by_email = format_slack_info_by_email(users)

Expand All @@ -60,7 +60,7 @@ def get_slack_user_list(
integration: Integration | RpcIntegration,
organization: Organization | RpcOrganization | None = None,
kwargs: dict[str, Any] | None = None,
) -> Iterable[dict[str, Any]]:
) -> Generator[list[dict[str, Any]]]:
sdk_client = SlackSdkClient(integration_id=integration.id)
try:
users_list = (
Expand All @@ -71,9 +71,7 @@ def get_slack_user_list(
metrics.incr(SLACK_UTILS_GET_USER_LIST_SUCCESS_DATADOG_METRIC, sample_rate=1.0)

for page in users_list:
users: dict[str, Any] = page.get("members")

yield users
yield page["members"]
except SlackApiError as e:
metrics.incr(SLACK_UTILS_GET_USER_LIST_FAILURE_DATADOG_METRIC, sample_rate=1.0)
_logger.info(
Expand Down

0 comments on commit d9a1b8c

Please sign in to comment.