Skip to content

Commit 970c633

Browse files
committed
test(rules): Improve type coverage
1 parent ed0a658 commit 970c633

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

src/sentry/rules/actions/integrations/create_ticket/utils.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import logging
44
from collections.abc import Callable, Sequence
5+
from typing import Any, cast
56

67
from rest_framework.response import Response
78

@@ -109,18 +110,18 @@ def create_issue(event: GroupEvent, futures: Sequence[RuleFuture]) -> None:
109110
organization = event.group.project.organization
110111

111112
for future in futures:
112-
rule_id = future.rule.id
113-
data = future.kwargs.get("data")
114-
provider = future.kwargs.get("provider")
115-
integration_id = future.kwargs.get("integration_id")
116-
generate_footer = future.kwargs.get("generate_footer")
113+
rule_id: int = future.rule.id
114+
data = cast(dict[str, Any], future.kwargs.get("data"))
115+
provider = cast(str, future.kwargs.get("provider"))
116+
integration_id = cast(str, future.kwargs.get("integration_id"))
117+
generate_footer = cast(Callable[[str], str], future.kwargs.get("generate_footer"))
117118

118119
# If we invoked this handler from the notification action, we need to replace the rule_id with the legacy_rule_id, so we link notifications correctly
119120
action_id = None
120121
if features.has("organizations:workflow-engine-trigger-actions", organization):
121122
# In the Notification Action, we store the rule_id in the action_id field
122123
action_id = rule_id
123-
rule_id = data.get("legacy_rule_id")
124+
rule_id = cast(int, data.get("legacy_rule_id"))
124125

125126
integration = integration_service.get_integration(
126127
integration_id=integration_id,

src/sentry/rules/base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
import abc
44
import logging
5-
from collections import namedtuple
65
from collections.abc import Callable, MutableMapping, Sequence
7-
from typing import TYPE_CHECKING, Any, ClassVar
6+
from typing import TYPE_CHECKING, Any, ClassVar, NamedTuple
87

98
from django import forms
109

@@ -48,10 +47,14 @@
4847
- [ACTION:I want to group events when] [RULE:an event matches [FORM]]
4948
"""
5049

50+
5151
# Encapsulates a reference to the callback, including arguments. The `key`
5252
# attribute may be specifically used to key the callbacks when they are
5353
# collated during rule processing.
54-
CallbackFuture = namedtuple("CallbackFuture", ["callback", "kwargs", "key"])
54+
class CallbackFuture(NamedTuple):
55+
callback: Callable[[GroupEvent, Sequence[RuleFuture]], None]
56+
kwargs: dict[str, Any]
57+
key: str | None
5558

5659

5760
class RuleBase(abc.ABC):

src/sentry/sentry_apps/tasks/sentry_apps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ def notify_sentry_app(event: GroupEvent, futures: Sequence[RuleFuture]):
667667

668668
# If the future comes from a rule with a UI component form in the schema, append the issue alert payload
669669
# TODO(ecosystem): We need to change this payload format after alerts create issues
670-
id = f.rule.id
670+
id: str | int = f.rule.id
671671

672672
# if we are using the new workflow engine, we need to use the legacy rule id
673673
# Ignore test notifications

src/sentry/types/rules.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
from collections import namedtuple
21
from dataclasses import dataclass
2+
from typing import Any, NamedTuple
33

4-
RuleFuture = namedtuple("RuleFuture", ["rule", "kwargs"])
4+
from sentry.models.rule import Rule
5+
6+
7+
class RuleFuture(NamedTuple):
8+
rule: Rule
9+
kwargs: dict[str, Any]
510

611

712
@dataclass

0 commit comments

Comments
 (0)