Skip to content

Commit

Permalink
ref: fix typing for group serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile-sentry committed Jan 17, 2025
1 parent 269cfd1 commit a00bd87
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 161 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ module = [
"sentry.api.permissions",
"sentry.api.serializers.models.auth_provider",
"sentry.api.serializers.models.event",
"sentry.api.serializers.models.group",
"sentry.api.serializers.models.group_stream",
"sentry.api.serializers.models.role",
"sentry.auth.helper",
Expand Down
3 changes: 2 additions & 1 deletion src/sentry/api/endpoints/organization_tagkey_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sentry.api.utils import handle_query_errors
from sentry.snuba.dataset import Dataset
from sentry.tagstore.base import TAG_KEY_RE
from sentry.tagstore.types import TagValue


def validate_sort_field(field_name: str) -> str:
Expand Down Expand Up @@ -50,7 +51,7 @@ def get(self, request: Request, organization, key) -> Response:
# still used by events v1 which doesn't require global views
snuba_params = self.get_snuba_params(request, organization, check_global_views=False)
except NoProjects:
paginator = SequencePaginator([])
paginator: SequencePaginator[TagValue] = SequencePaginator([])
else:
with handle_query_errors():
paginator = tagstore.backend.get_tag_value_paginator_for_projects(
Expand Down
18 changes: 12 additions & 6 deletions src/sentry/api/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import functools
import logging
import math
from collections.abc import Callable, Sequence
from collections.abc import Callable, Iterable, Sequence
from datetime import datetime, timezone
from typing import Any
from urllib.parse import quote
Expand Down Expand Up @@ -410,11 +410,17 @@ def reverse_bisect_left(a, x, lo=0, hi=None):
return lo


class SequencePaginator:
def __init__(self, data, reverse=False, max_limit=MAX_LIMIT, on_results=None):
self.scores, self.values = (
map(list, zip(*sorted(data, reverse=reverse))) if data else ([], [])
)
class SequencePaginator[T]:
def __init__(
self,
data: Iterable[tuple[int, T]],
reverse: bool = False,
max_limit: int = MAX_LIMIT,
on_results=None,
):
data = sorted(data, reverse=reverse)
self.scores = [score for score, _ in data]
self.values = [value for _, value in data]
self.reverse = reverse
self.search = functools.partial(
reverse_bisect_left if reverse else bisect.bisect_left, self.scores
Expand Down
Loading

0 comments on commit a00bd87

Please sign in to comment.