Browse Source

ref: fix typing in a few files (#61422)

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

+ 0 - 5
pyproject.toml

@@ -156,7 +156,6 @@ module = [
     "sentry.api.endpoints.group_event_details",
     "sentry.api.endpoints.group_events",
     "sentry.api.endpoints.group_external_issues",
-    "sentry.api.endpoints.group_hashes",
     "sentry.api.endpoints.group_hashes_split",
     "sentry.api.endpoints.group_integration_details",
     "sentry.api.endpoints.group_integrations",
@@ -168,7 +167,6 @@ module = [
     "sentry.api.endpoints.index",
     "sentry.api.endpoints.integration_features",
     "sentry.api.endpoints.integrations.install_request",
-    "sentry.api.endpoints.integrations.plugins.configs_index",
     "sentry.api.endpoints.integrations.sentry_apps.details",
     "sentry.api.endpoints.integrations.sentry_apps.index",
     "sentry.api.endpoints.integrations.sentry_apps.installation.details",
@@ -187,7 +185,6 @@ module = [
     "sentry.api.endpoints.organization_code_mapping_details",
     "sentry.api.endpoints.organization_code_mappings",
     "sentry.api.endpoints.organization_dashboard_details",
-    "sentry.api.endpoints.organization_dashboards",
     "sentry.api.endpoints.organization_details",
     "sentry.api.endpoints.organization_events",
     "sentry.api.endpoints.organization_events_facets",
@@ -519,7 +516,6 @@ module = [
     "sentry.rules.actions.integrations.create_ticket.form",
     "sentry.rules.actions.integrations.create_ticket.utils",
     "sentry.rules.actions.notify_event_service",
-    "sentry.rules.conditions.event_attribute",
     "sentry.rules.conditions.event_frequency",
     "sentry.rules.conditions.level",
     "sentry.rules.conditions.tagged_event",
@@ -529,7 +525,6 @@ module = [
     "sentry.scim.endpoints.members",
     "sentry.scim.endpoints.teams",
     "sentry.scim.endpoints.utils",
-    "sentry.sdk_updates",
     "sentry.search.events.builder.discover",
     "sentry.search.events.builder.errors",
     "sentry.search.events.builder.metrics",

+ 1 - 1
src/sentry/api/endpoints/group_hashes.py

@@ -57,7 +57,7 @@ class GroupHashesEndpoint(GroupEndpoint):
 
     def delete(self, request: Request, group) -> Response:
         id_list = request.GET.getlist("id")
-        if id_list is None:
+        if not id_list:
             return Response()
 
         hash_list = list(

+ 3 - 1
src/sentry/api/endpoints/integrations/plugins/configs_index.py

@@ -1,3 +1,5 @@
+from __future__ import annotations
+
 from django.http.response import Http404
 from rest_framework.request import Request
 from rest_framework.response import Response
@@ -66,7 +68,7 @@ class OrganizationPluginsConfigsEndpoint(OrganizationEndpoint):
             },
         }
         """
-        info_by_plugin_project = {}
+        info_by_plugin_project: dict[str, dict[int, dict[str, bool]]] = {}
         for project_option in project_options:
             [slug, field] = project_option.key.split(":")
             project_id = project_option.project_id

+ 6 - 6
src/sentry/api/endpoints/organization_dashboards.py

@@ -1,3 +1,5 @@
+from __future__ import annotations
+
 import re
 
 from django.db import IntegrityError, router, transaction
@@ -67,6 +69,7 @@ class OrganizationDashboardsEndpoint(OrganizationEndpoint):
         else:
             desc = False
 
+        order_by: list[Case | str]
         if sort_by == "title":
             order_by = [
                 "-title" if desc else "title",
@@ -74,7 +77,7 @@ class OrganizationDashboardsEndpoint(OrganizationEndpoint):
             ]
 
         elif sort_by == "dateCreated":
-            order_by = "-date_added" if desc else "date_added"
+            order_by = ["-date_added" if desc else "date_added"]
 
         elif sort_by == "mostPopular":
             order_by = [
@@ -83,7 +86,7 @@ class OrganizationDashboardsEndpoint(OrganizationEndpoint):
             ]
 
         elif sort_by == "recentlyViewed":
-            order_by = "last_visited" if desc else "-last_visited"
+            order_by = ["last_visited" if desc else "-last_visited"]
 
         elif sort_by == "mydashboards":
             order_by = [
@@ -102,10 +105,7 @@ class OrganizationDashboardsEndpoint(OrganizationEndpoint):
             ]
 
         else:
-            order_by = "title"
-
-        if not isinstance(order_by, list):
-            order_by = [order_by]
+            order_by = ["title"]
 
         dashboards = dashboards.order_by(*order_by)
 

+ 18 - 16
src/sentry/rules/conditions/event_attribute.py

@@ -1,3 +1,5 @@
+from __future__ import annotations
+
 from typing import Any, Dict, Sequence
 
 from django import forms
@@ -74,7 +76,7 @@ class EventAttributeCondition(EventCondition):
         "value": {"type": "string", "placeholder": "value"},
     }
 
-    def _get_attribute_values(self, event: GroupEvent, attr: str) -> Sequence[str]:
+    def _get_attribute_values(self, event: GroupEvent, attr: str) -> Sequence[object | None]:
         # TODO(dcramer): we should validate attributes (when we can) before
         path = attr.split(".")
 
@@ -156,9 +158,9 @@ class EventAttributeCondition(EventCondition):
             return [event.data["sdk"].get(path[1])]
 
         elif path[0] == "stacktrace":
-            stacks = event.interfaces.get("stacktrace")
-            if stacks:
-                stacks = [stacks]
+            stacktrace = event.interfaces.get("stacktrace")
+            if stacktrace:
+                stacks = [stacktrace]
             else:
                 stacks = [
                     e.stacktrace for e in event.interfaces["exception"].values if e.stacktrace
@@ -218,7 +220,7 @@ class EventAttributeCondition(EventCondition):
         }
         return self.label.format(**data)
 
-    def _passes(self, attribute_values: Sequence[Any]) -> bool:
+    def _passes(self, attribute_values: Sequence[object | None]) -> bool:
         match = self.get_option("match")
         value = self.get_option("value")
 
@@ -227,61 +229,61 @@ class EventAttributeCondition(EventCondition):
 
         value = value.lower()
 
-        attribute_values = [str(v).lower() for v in attribute_values if v is not None]
+        values = [str(v).lower() for v in attribute_values if v is not None]
 
         if match == MatchType.EQUAL:
-            for a_value in attribute_values:
+            for a_value in values:
                 if a_value == value:
                     return True
             return False
 
         elif match == MatchType.NOT_EQUAL:
-            for a_value in attribute_values:
+            for a_value in values:
                 if a_value == value:
                     return False
             return True
 
         elif match == MatchType.STARTS_WITH:
-            for a_value in attribute_values:
+            for a_value in values:
                 if a_value.startswith(value):
                     return True
             return False
 
         elif match == MatchType.NOT_STARTS_WITH:
-            for a_value in attribute_values:
+            for a_value in values:
                 if a_value.startswith(value):
                     return False
             return True
 
         elif match == MatchType.ENDS_WITH:
-            for a_value in attribute_values:
+            for a_value in values:
                 if a_value.endswith(value):
                     return True
             return False
 
         elif match == MatchType.NOT_ENDS_WITH:
-            for a_value in attribute_values:
+            for a_value in values:
                 if a_value.endswith(value):
                     return False
             return True
 
         elif match == MatchType.CONTAINS:
-            for a_value in attribute_values:
+            for a_value in values:
                 if value in a_value:
                     return True
             return False
 
         elif match == MatchType.NOT_CONTAINS:
-            for a_value in attribute_values:
+            for a_value in values:
                 if value in a_value:
                     return False
             return True
 
         elif match == MatchType.IS_SET:
-            return bool(attribute_values)
+            return bool(values)
 
         elif match == MatchType.NOT_SET:
-            return not attribute_values
+            return not values
 
         raise RuntimeError("Invalid Match")
 

+ 12 - 1
src/sentry/sdk_updates.py

@@ -1,8 +1,11 @@
+from __future__ import annotations
+
 import logging
 
 from django.conf import settings
 from django.core.cache import cache
 from packaging.version import Version
+from typing_extensions import TypedDict
 
 from sentry.tasks.release_registry import SDK_INDEX_CACHE_KEY
 from sentry.utils.safe import get_path
@@ -143,7 +146,15 @@ class ChangeSDKSuggestion(Suggestion):
         return new_state
 
 
-SDK_SUPPORTED_MODULES = [
+class SupportedModule(TypedDict):
+    sdk_name: str
+    sdk_version_added: str
+    module_name: str
+    module_version_min: str
+    suggestion: Suggestion
+
+
+SDK_SUPPORTED_MODULES: list[SupportedModule] = [
     {
         "sdk_name": "sentry.python",
         "sdk_version_added": "0.3.2",