Repository: getsentry/sentry

Issue:
Fix typing for `sentry.rules.processor`
Many files related to post-process are skipping type checks.

* Remove the file from [sentry/pyproject.toml](https://github.com/getsentry/sentry/blob/b7810a9dca4b57afd2858903a6a9ec7ab50cdead/pyproject.toml)
* Run `mypy sentry.rules.processor` and fix the typing errors

From https://github.com/getsentry/sentry/issues/55193


Discussion:

Resolving patch:
diff --git a/src/sentry/rules/processor.py b/src/sentry/rules/processor.py
--- a/src/sentry/rules/processor.py
+++ b/src/sentry/rules/processor.py
@@ -27,7 +27,9 @@
 from sentry.models.rule import Rule
 from sentry.models.rulesnooze import RuleSnooze
 from sentry.rules import EventState, history, rules
+from sentry.rules.actions.base import EventAction
 from sentry.rules.conditions.base import EventCondition
+from sentry.rules.filters.base import EventFilter
 from sentry.types.rules import RuleFuture
 from sentry.utils.hashlib import hash_values
 from sentry.utils.safe import safe_execute
@@ -143,16 +145,22 @@ def bulk_get_rule_status(self, rules: Sequence[Rule]) -> Mapping[int, GroupRuleS
         return rule_statuses
 
     def condition_matches(
-        self, condition: Mapping[str, Any], state: EventState, rule: Rule
+        self, condition: dict[str, Any], state: EventState, rule: Rule
     ) -> bool | None:
         condition_cls = rules.get(condition["id"])
         if condition_cls is None:
             self.logger.warning("Unregistered condition %r", condition["id"])
             return None
 
-        condition_inst: EventCondition = condition_cls(self.project, data=condition, rule=rule)
+        condition_inst = condition_cls(self.project, data=condition, rule=rule)
+        if not isinstance(condition_inst, (EventCondition, EventFilter)):
+            self.logger.warning("Unregistered condition %r", condition["id"])
+            return None
         passes: bool = safe_execute(
-            condition_inst.passes, self.event, state, _with_transaction=False
+            condition_inst.passes,
+            self.event,
+            state,
+            _with_transaction=False,
         )
         return passes
 
@@ -274,6 +282,9 @@ def activate_downstream_actions(
                 continue
 
             action_inst = action_cls(self.project, data=action, rule=rule)
+            if not isinstance(action_inst, EventAction):
+                self.logger.warning("Unregistered action %r", action["id"])
+                continue
 
             results = safe_execute(
                 action_inst.after,


Test patch:
diff --git a/tests/sentry/tasks/test_post_process.py b/tests/sentry/tasks/test_post_process.py
--- a/tests/sentry/tasks/test_post_process.py
+++ b/tests/sentry/tasks/test_post_process.py
@@ -42,6 +42,7 @@
 from sentry.ownership.grammar import Matcher, Owner, Rule, dump_schema
 from sentry.replays.lib import kafka as replays_kafka
 from sentry.rules import init_registry
+from sentry.rules.actions.base import EventAction
 from sentry.services.hybrid_cloud.user.service import user_service
 from sentry.silo import unguarded_write
 from sentry.tasks.derive_code_mappings import SUPPORTED_LANGUAGES
@@ -396,8 +397,8 @@ def test_rule_processor_buffer_values(self):
             "sentry.rules.processor.rules", init_registry()
         ) as rules:
             MockAction = mock.Mock()
-            MockAction.rule_type = "action/event"
             MockAction.id = "tests.sentry.tasks.post_process.tests.MockAction"
+            MockAction.return_value = mock.Mock(spec=EventAction)
             MockAction.return_value.after.return_value = []
             rules.add(MockAction)