Browse Source

ref: fix type ignores in organization_events_trends_v2 (#67687)

<!-- Describe your PR here. -->
anthony sottile 11 months ago
parent
commit
1a4714079c

+ 6 - 6
src/sentry/api/bases/organization_events.py

@@ -56,19 +56,19 @@ class OrganizationEventsEndpointBase(OrganizationEndpoint):
             )
         )
 
-    def get_equation_list(self, organization: Organization, request: Request) -> Sequence[str]:
+    def get_equation_list(self, organization: Organization, request: Request) -> list[str]:
         """equations have a prefix so that they can be easily included alongside our existing fields"""
         return [
             strip_equation(field) for field in request.GET.getlist("field")[:] if is_equation(field)
         ]
 
-    def get_field_list(self, organization: Organization, request: Request) -> Sequence[str]:
+    def get_field_list(self, organization: Organization, request: Request) -> list[str]:
         return [field for field in request.GET.getlist("field")[:] if not is_equation(field)]
 
-    def get_team_ids(self, request: Request, organization: Organization) -> Sequence[int]:
+    def get_team_ids(self, request: Request, organization: Organization) -> list[int]:
         return [team.id for team in self.get_teams(request, organization)]
 
-    def get_teams(self, request: Request, organization: Organization) -> Sequence[Team]:
+    def get_teams(self, request: Request, organization: Organization) -> list[Team]:
         if not request.user:
             return []
 
@@ -158,12 +158,12 @@ class OrganizationEventsEndpointBase(OrganizationEndpoint):
             return params
 
     def get_orderby(self, request: Request) -> Sequence[str] | None:
-        sort: Sequence[str] = request.GET.getlist("sort")
+        sort = request.GET.getlist("sort")
         if sort:
             return sort
         # Deprecated. `sort` should be used as it is supported by
         # more endpoints.
-        orderby: Sequence[str] = request.GET.getlist("orderby")
+        orderby = request.GET.getlist("orderby")
         if orderby:
             return orderby
         return None

+ 4 - 4
src/sentry/api/endpoints/organization_events_trends_v2.py

@@ -1,7 +1,7 @@
 import logging
 import re
 from concurrent.futures import ThreadPoolExecutor
-from typing import Any, cast
+from typing import Any
 
 import sentry_sdk
 from rest_framework.exceptions import ParseError
@@ -93,7 +93,7 @@ class OrganizationEventsNewTrendsStatsEndpoint(OrganizationEventsV2EndpointBase)
         top_trending_transactions = {}
 
         def get_top_events(user_query, params, event_limit, referrer):
-            top_event_columns = cast(list[str], selected_columns[:])
+            top_event_columns = selected_columns[:]
             top_event_columns.append("count()")
             top_event_columns.append("project_id")
 
@@ -129,7 +129,7 @@ class OrganizationEventsNewTrendsStatsEndpoint(OrganizationEventsV2EndpointBase)
             ]
             queries = [generate_top_transaction_query(t_e) for t_e in split_top_events]
 
-            timeseries_columns = cast(list[str], selected_columns[:])
+            timeseries_columns = selected_columns[:]
             timeseries_columns.append(trend_function)
 
             # When all projects or my projects options selected,
@@ -170,7 +170,7 @@ class OrganizationEventsNewTrendsStatsEndpoint(OrganizationEventsV2EndpointBase)
                     "project_id": item["project_id"],
                 }
 
-            for row in result.get("data", []):  # type: ignore[union-attr]
+            for row in result.get("data", []):
                 result_key = create_result_key(row, translated_groupby, {})
                 if result_key in results:
                     results[result_key]["data"].append(row)

+ 1 - 3
src/sentry/replays/endpoints/organization_replay_events_meta.py

@@ -1,5 +1,3 @@
-from collections.abc import Sequence
-
 from rest_framework.request import Request
 from rest_framework.response import Response
 
@@ -29,7 +27,7 @@ class OrganizationReplayEventsMetaEndpoint(OrganizationEventsV2EndpointBase):
         "GET": ApiPublishStatus.PRIVATE,
     }
 
-    def get_field_list(self, organization: Organization, request: Request) -> Sequence[str]:
+    def get_field_list(self, organization: Organization, request: Request) -> list[str]:
         return [
             "error.type",
             "error.value",  # Deprecated, use title instead. See replayDataUtils.tsx

+ 45 - 2
src/sentry/snuba/metrics_performance.py

@@ -3,7 +3,7 @@ from __future__ import annotations
 import logging
 from collections.abc import Sequence
 from datetime import timedelta
-from typing import Any
+from typing import Any, Literal, overload
 
 import sentry_sdk
 from snuba_sdk import Column
@@ -87,6 +87,7 @@ def query(
         return results
 
 
+@overload
 def bulk_timeseries_query(
     selected_columns: Sequence[str],
     queries: list[str],
@@ -102,7 +103,49 @@ def bulk_timeseries_query(
     on_demand_metrics_enabled: bool = False,
     on_demand_metrics_type: MetricSpecType | None = None,
     groupby: Column | None = None,
-    apply_formatting: bool | None = True,
+    *,
+    apply_formatting: Literal[False],
+) -> EventsResponse:
+    ...
+
+
+@overload
+def bulk_timeseries_query(
+    selected_columns: Sequence[str],
+    queries: list[str],
+    params: ParamsType,
+    rollup: int,
+    referrer: str,
+    zerofill_results: bool = True,
+    allow_metric_aggregates=True,
+    comparison_delta: timedelta | None = None,
+    functions_acl: list[str] | None = None,
+    has_metrics: bool = True,
+    use_metrics_layer: bool = False,
+    on_demand_metrics_enabled: bool = False,
+    on_demand_metrics_type: MetricSpecType | None = None,
+    groupby: Column | None = None,
+) -> SnubaTSResult:
+    ...
+
+
+def bulk_timeseries_query(
+    selected_columns: Sequence[str],
+    queries: list[str],
+    params: ParamsType,
+    rollup: int,
+    referrer: str,
+    zerofill_results: bool = True,
+    allow_metric_aggregates=True,
+    comparison_delta: timedelta | None = None,
+    functions_acl: list[str] | None = None,
+    has_metrics: bool = True,
+    use_metrics_layer: bool = False,
+    on_demand_metrics_enabled: bool = False,
+    on_demand_metrics_type: MetricSpecType | None = None,
+    groupby: Column | None = None,
+    *,
+    apply_formatting: bool = True,
 ) -> SnubaTSResult | EventsResponse:
     """
     High-level API for doing *bulk* arbitrary user timeseries queries against events.