Browse Source

ref: fix a few mypy issues (#54344)

<!-- Describe your PR here. -->
anthony sottile 1 year ago
parent
commit
45189df6a1

+ 0 - 46
pyproject.toml

@@ -228,7 +228,6 @@ module = [
     "sentry.api.endpoints.organization_events_facets_stats_performance",
     "sentry.api.endpoints.organization_events_has_measurements",
     "sentry.api.endpoints.organization_events_meta",
-    "sentry.api.endpoints.organization_events_span_ops",
     "sentry.api.endpoints.organization_events_spans_performance",
     "sentry.api.endpoints.organization_events_stats",
     "sentry.api.endpoints.organization_events_trace",
@@ -239,7 +238,6 @@ module = [
     "sentry.api.endpoints.organization_index",
     "sentry.api.endpoints.organization_integration_repos",
     "sentry.api.endpoints.organization_issues_count",
-    "sentry.api.endpoints.organization_member",
     "sentry.api.endpoints.organization_member.details",
     "sentry.api.endpoints.organization_member.index",
     "sentry.api.endpoints.organization_member.requests.invite.details",
@@ -475,7 +473,6 @@ module = [
     "sentry.integrations.gitlab.issues",
     "sentry.integrations.gitlab.repository",
     "sentry.integrations.gitlab.webhooks",
-    "sentry.integrations.jira",
     "sentry.integrations.jira.actions.create_ticket",
     "sentry.integrations.jira.actions.form",
     "sentry.integrations.jira.client",
@@ -495,7 +492,6 @@ module = [
     "sentry.integrations.mixins.issues",
     "sentry.integrations.mixins.notifications",
     "sentry.integrations.mixins.repositories",
-    "sentry.integrations.msteams",
     "sentry.integrations.msteams.actions.form",
     "sentry.integrations.msteams.card_builder.base",
     "sentry.integrations.msteams.card_builder.issues",
@@ -506,12 +502,10 @@ module = [
     "sentry.integrations.msteams.notifications",
     "sentry.integrations.msteams.webhook",
     "sentry.integrations.notifications",
-    "sentry.integrations.pagerduty",
     "sentry.integrations.pagerduty.actions.form",
     "sentry.integrations.pagerduty.client",
     "sentry.integrations.pagerduty.integration",
     "sentry.integrations.pipeline",
-    "sentry.integrations.slack",
     "sentry.integrations.slack.actions.form",
     "sentry.integrations.slack.client",
     "sentry.integrations.slack.integration",
@@ -536,7 +530,6 @@ module = [
     "sentry.integrations.vercel.client",
     "sentry.integrations.vercel.integration",
     "sentry.integrations.vercel.webhook",
-    "sentry.integrations.vsts",
     "sentry.integrations.vsts.client",
     "sentry.integrations.vsts.integration",
     "sentry.integrations.vsts.issues",
@@ -682,7 +675,6 @@ module = [
     "sentry.rules.history.endpoints.project_rule_stats",
     "sentry.rules.history.preview",
     "sentry.rules.processor",
-    "sentry.rules.registry",
     "sentry.runner.commands.migrations",
     "sentry.runner.importer",
     "sentry.runner.initializer",
@@ -721,7 +713,6 @@ module = [
     "sentry.similarity.backends.dummy",
     "sentry.similarity.features",
     "sentry.snuba.discover",
-    "sentry.snuba.entity_subscription",
     "sentry.snuba.issue_platform",
     "sentry.snuba.metrics",
     "sentry.snuba.metrics.datasource",
@@ -1061,59 +1052,22 @@ module = [
     "tests.sentry.release_health.release_monitor.test_sessions",
     "tests.sentry.release_health.test_tasks",
     "tests.sentry.replays.consumers.test_recording",
-    "tests.sentry.replays.test_organization_replay_count",
     "tests.sentry.replays.test_project_replay_recording_segment_details",
     "tests.sentry.replays.test_project_replay_recording_segment_index",
     "tests.sentry.replays.unit.test_dead_click_issue",
-    "tests.sentry.replays.unit.test_ingest_dom_index",
-    "tests.sentry.rules.conditions.test_event_attribute",
-    "tests.sentry.rules.conditions.test_level_event",
-    "tests.sentry.rules.conditions.test_tagged_event",
-    "tests.sentry.rules.filters.test_issue_category",
-    "tests.sentry.rules.history.endpoints.test_project_rule_preview",
-    "tests.sentry.rules.test_processor",
-    "tests.sentry.search.events.builder.test_discover",
     "tests.sentry.search.events.builder.test_metrics",
     "tests.sentry.search.events.test_fields",
-    "tests.sentry.search.events.test_filter",
-    "tests.sentry.search.test_utils",
     "tests.sentry.sentry_apps.test_sentry_app_creator",
-    "tests.sentry.sentry_apps.test_sentry_app_installation_creator",
-    "tests.sentry.sentry_apps.test_sentry_app_installation_token_creator",
-    "tests.sentry.sentry_apps.test_sentry_app_updater",
     "tests.sentry.sentry_metrics.consumers.test_slicing_router",
     "tests.sentry.sentry_metrics.limiters.test_writes_limiter",
-    "tests.sentry.sentry_metrics.test_all_indexers",
     "tests.sentry.sentry_metrics.test_base_indexer",
     "tests.sentry.sentry_metrics.test_batch",
-    "tests.sentry.sentry_metrics.test_indexer_cache",
     "tests.sentry.sentry_metrics.test_multiprocess_steps",
-    "tests.sentry.sentry_metrics.test_postgres_indexer",
-    "tests.sentry.sentry_metrics.test_strings",
-    "tests.sentry.snuba.metrics.test_metrics_layer.test_release_health",
-    "tests.sentry.snuba.metrics.test_mqb_query_transformer",
-    "tests.sentry.snuba.metrics.test_query_builder",
     "tests.sentry.snuba.metrics.test_snql",
-    "tests.sentry.snuba.metrics.test_utils",
-    "tests.sentry.snuba.test_discover_query",
-    "tests.sentry.snuba.test_discover_timeseries_query",
-    "tests.sentry.snuba.test_outcomes",
-    "tests.sentry.snuba.test_profiles",
-    "tests.sentry.snuba.test_query_subscription_consumer",
     "tests.sentry.snuba.test_tasks",
     "tests.sentry.tagstore.test_types",
-    "tests.sentry.tasks.deletion.test_groups",
     "tests.sentry.tasks.deletion.test_scheduled",
-    "tests.sentry.tasks.integrations.github.test_pr_comment",
-    "tests.sentry.tasks.test_derive_code_mappings",
-    "tests.sentry.tasks.test_groupowner",
-    "tests.sentry.tasks.test_merge",
     "tests.sentry.tasks.test_post_process",
-    "tests.sentry.tasks.test_reprocessing2",
-    "tests.sentry.tasks.test_sentry_apps",
-    "tests.sentry.tasks.test_servicehooks",
-    "tests.sentry.tasks.test_store",
-    "tests.sentry.test_stacktraces",
     "tests.sentry.web.test_client_config",
     "tests.snuba.rules.conditions.test_event_frequency",
     "tests.snuba.sessions.test_sessions",

+ 2 - 1
src/sentry/api/endpoints/organization_member/__init__.py

@@ -3,10 +3,11 @@ from __future__ import annotations
 from typing import Collection, List, Tuple
 
 from django.db import transaction
+from rest_framework import status
 from rest_framework.request import Request
 
 from sentry import roles
-from sentry.api.exceptions import SentryAPIException, status
+from sentry.api.exceptions import SentryAPIException
 from sentry.auth.access import Access
 from sentry.auth.superuser import is_active_superuser
 from sentry.locks import locks

+ 12 - 2
src/sentry/eventstore/models.py

@@ -6,7 +6,17 @@ import string
 from copy import deepcopy
 from datetime import datetime, timezone
 from hashlib import md5
-from typing import TYPE_CHECKING, Any, Mapping, MutableMapping, Optional, Sequence, Tuple, cast
+from typing import (
+    TYPE_CHECKING,
+    Any,
+    Generator,
+    Mapping,
+    MutableMapping,
+    Optional,
+    Sequence,
+    Tuple,
+    cast,
+)
 
 import sentry_sdk
 from dateutil.parser import parse as parse_date
@@ -676,7 +686,7 @@ class Event(BaseEvent):
         self._groups_cache = values
         self._group_ids = [group.id for group in values] if values else None
 
-    def build_group_events(self):
+    def build_group_events(self) -> Generator[GroupEvent, None, None]:
         """
         Yields a GroupEvent for each Group associated with this Event.
         """

+ 1 - 1
src/sentry/integrations/discord/__init__.py

@@ -12,4 +12,4 @@ from .urls import *  # noqa: F401,F403
 from .utils import *  # noqa: F401,F403
 from .views import *  # noqa: F401,F403
 
-rules.add(DiscordNotifyServiceAction)  # type: ignore
+rules.add(DiscordNotifyServiceAction)

+ 1 - 1
src/sentry/mail/actions.py

@@ -31,7 +31,7 @@ class NotifyEmailAction(EventAction):
 
     def render_label(self) -> str:
         if "fallthroughType" not in self.data:
-            self.data["fallthroughType"] = FallthroughChoiceType.ACTIVE_MEMBERS.value
+            self.data = {**self.data, "fallthroughType": FallthroughChoiceType.ACTIVE_MEMBERS.value}
         return self.label.format(**self.data)
 
     def after(self, event, state):

+ 3 - 3
src/sentry/replays/query.py

@@ -133,7 +133,7 @@ def query_replay_instance(
 
 
 def query_replays_dataset(
-    project_ids: List[str],
+    project_ids: List[int],
     start: datetime,
     end: datetime,
     where: List[Condition],
@@ -199,7 +199,7 @@ def query_replays_dataset(
 
 
 def query_replays_dataset_with_subquery(
-    project_ids: List[str],
+    project_ids: List[int],
     start: datetime,
     end: datetime,
     environments: List[str],
@@ -347,7 +347,7 @@ def query_replays_count(
 
 
 def query_replays_dataset_tagkey_values(
-    project_ids: List[str],
+    project_ids: List[int],
     start: datetime,
     end: datetime,
     environment: str | None,

+ 2 - 2
src/sentry/replays/usecases/ingest/dom_index.py

@@ -44,7 +44,7 @@ class ReplayActionsEventPayload(TypedDict):
 
 
 class ReplayActionsEvent(TypedDict):
-    payload: List[bytes]
+    payload: List[int]
     project_id: int
     replay_id: str
     retention_days: int
@@ -92,7 +92,7 @@ def create_replay_actions_event(
         "replay_id": replay_id,
         "project_id": project_id,
         "retention_days": retention_days,
-        "payload": list(json.dumps(payload).encode()),  # type: ignore
+        "payload": list(json.dumps(payload).encode()),
     }
 
 

+ 2 - 2
src/sentry/roles/manager.py

@@ -129,8 +129,8 @@ class RoleLevel(Generic[R]):
 class RoleManager:
     def __init__(
         self,
-        org_config: Iterable[Mapping[str, str]],
-        team_config: Iterable[Mapping[str, str]],
+        org_config: Iterable[Mapping[str, Any]],
+        team_config: Iterable[Mapping[str, Any]],
         default_org_role: str | None = None,
     ) -> None:
         self.organization_roles: RoleLevel[OrganizationRole] = RoleLevel(

+ 1 - 1
src/sentry/rules/actions/integrations/create_ticket/base.py

@@ -24,7 +24,7 @@ class TicketEventAction(IntegrationEventAction, abc.ABC):
         ]
 
         if not self.get_integration_id() and integration_choices:
-            self.data[self.integration_key] = integration_choices[0][0]
+            self.data = {**self.data, self.integration_key: integration_choices[0][0]}
 
         self.form_fields = {
             self.integration_key: {

+ 6 - 12
src/sentry/rules/base.py

@@ -3,7 +3,7 @@ from __future__ import annotations
 import abc
 import logging
 from collections import namedtuple
-from typing import Any, Callable, Dict, MutableMapping, Sequence, Type
+from typing import Any, Callable, ClassVar, Dict, Mapping, Sequence, Type
 
 from django import forms
 
@@ -57,7 +57,7 @@ class RuleBase(abc.ABC):
     def __init__(
         self,
         project: Project,
-        data: MutableMapping[str, Any] | None = None,
+        data: Mapping[str, Any] | None = None,
         rule: Rule | None = None,
     ) -> None:
         self.project = project
@@ -65,15 +65,9 @@ class RuleBase(abc.ABC):
         self.had_data = data is not None
         self.rule = rule
 
-    @property
-    @abc.abstractmethod
-    def id(self) -> str:
-        pass
-
-    @property
-    @abc.abstractmethod
-    def label(self) -> str:
-        pass
+    id: ClassVar[str]
+    label: ClassVar[str]
+    rule_type: ClassVar[str]
 
     def is_enabled(self) -> bool:
         return True
@@ -82,7 +76,7 @@ class RuleBase(abc.ABC):
         return self.data.get(key, default)
 
     def get_form_instance(self) -> forms.Form:
-        data: MutableMapping[str, Any] | None = None
+        data: Mapping[str, Any] | None = None
         if self.had_data:
             data = self.data
         return self.form_cls(data)

Some files were not shown because too many files changed in this diff