Skip to content

Commit 64b3959

Browse files
authored
type src/sentry/api/helpers (#98013)
# Summary Typed a new module, 11 files fixed. # Test Plan `mypy` no errors
1 parent 9282aa3 commit 64b3959

File tree

14 files changed

+49
-24
lines changed

14 files changed

+49
-24
lines changed

pyproject.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,7 @@ module = [
358358
"sentry.api.endpoints.project_rules_configuration",
359359
"sentry.api.endpoints.release_thresholds.*",
360360
"sentry.api.event_search",
361-
"sentry.api.helpers.deprecation",
362-
"sentry.api.helpers.environments",
363-
"sentry.api.helpers.error_upsampling",
364-
"sentry.api.helpers.group_index.delete",
365-
"sentry.api.helpers.group_index.update",
366-
"sentry.api.helpers.source_map_helper",
361+
"sentry.api.helpers.*",
367362
"sentry.api.permissions",
368363
"sentry.api.serializers.models.organization_member.*",
369364
"sentry.api.serializers.rest_framework.group_notes",

src/sentry/api/bases/organization_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import itertools
4-
from collections.abc import Callable, Sequence
4+
from collections.abc import Callable, Iterable, Sequence
55
from datetime import timedelta
66
from typing import Any, cast
77
from urllib.parse import quote as urlquote
@@ -115,7 +115,7 @@ def get_teams(self, request: Request, organization: Organization) -> list[Team]:
115115
if not request.user:
116116
return []
117117

118-
teams = get_teams(request, organization)
118+
teams: Iterable[Team] = get_teams(request, organization)
119119
if not teams:
120120
teams = Team.objects.get_for_user(organization, request.user)
121121

src/sentry/api/helpers/default_inbound_filters.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
from collections.abc import Sequence
2+
13
from sentry.ingest import inbound_filters
4+
from sentry.models.organization import Organization
5+
from sentry.models.project import Project
26

37

48
# Turns on certain inbound filters by default for project.
59
def set_default_inbound_filters(
6-
project,
7-
organization,
8-
filters=(
10+
project: Project,
11+
organization: Organization,
12+
filters: Sequence[str] = (
913
"browser-extensions",
1014
"legacy-browsers",
1115
"web-crawlers",
1216
"filtered-transaction",
1317
),
14-
):
18+
) -> None:
1519

1620
browser_subfilters = [
1721
"ie",

src/sentry/api/helpers/group_index/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections.abc import Callable, Mapping
22
from typing import Any
33

4+
from sentry.models.group import Group
45
from sentry.utils.cursors import CursorResult
56

67
"""TODO(mgaeta): This directory is incorrectly suffixed '_index'."""
@@ -16,7 +17,7 @@
1617
# `sentry.api.paginator.BasePaginator.get_result`.
1718
SEARCH_MAX_HITS = 1000
1819

19-
SearchFunction = Callable[[Mapping[str, Any]], tuple[CursorResult, Mapping[str, Any]]]
20+
SearchFunction = Callable[[Mapping[str, Any]], tuple[CursorResult[Group], Mapping[str, Any]]]
2021

2122
__all__ = (
2223
"ACTIVITIES_COUNT",

src/sentry/api/helpers/group_index/validators/group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sentry.api.fields import ActorField
88
from sentry.api.helpers.group_index.validators.inbox_details import InboxDetailsValidator
99
from sentry.api.helpers.group_index.validators.status_details import StatusDetailsValidator
10-
from sentry.models.group import STATUS_UPDATE_CHOICES
10+
from sentry.models.group import STATUS_UPDATE_CHOICES, Group
1111
from sentry.types.actor import Actor
1212
from sentry.types.group import SUBSTATUS_UPDATE_CHOICES, PriorityLevel
1313

@@ -23,7 +23,7 @@
2323
"snoozeDuration",
2424
]
2525
)
26-
class GroupValidator(serializers.Serializer):
26+
class GroupValidator(serializers.Serializer[Group]):
2727
inbox = serializers.BooleanField(
2828
help_text="If true, marks the issue as reviewed by the requestor."
2929
)

src/sentry/api/helpers/group_index/validators/in_commit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class InCommitResult(TypedDict):
1313

1414

1515
@extend_schema_serializer()
16-
class InCommitValidator(serializers.Serializer):
16+
class InCommitValidator(serializers.Serializer[InCommitResult]):
1717
commit = serializers.CharField(required=True, help_text="The SHA of the resolving commit.")
1818
repository = serializers.CharField(
1919
required=True, help_text="The name of the repository (as it appears in Sentry)."
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from typing import Never
2+
13
from rest_framework import serializers
24

35

4-
class InboxDetailsValidator(serializers.Serializer):
6+
class InboxDetailsValidator(serializers.Serializer[Never]):
57
# Support undo / snooze reasons
68
pass

src/sentry/api/helpers/group_index/validators/status_details.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class StatusDetailsResult(TypedDict):
2121

2222

2323
@extend_schema_serializer()
24-
class StatusDetailsValidator(serializers.Serializer):
24+
class StatusDetailsValidator(serializers.Serializer[StatusDetailsResult]):
2525
inNextRelease = serializers.BooleanField(
2626
help_text="If true, marks the issue as resolved in the next release."
2727
)

src/sentry/api/helpers/releases.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
from sentry.api.exceptions import ResourceDoesNotExist
22
from sentry.models.grouplink import GroupLink
33
from sentry.models.groupresolution import GroupResolution
4+
from sentry.models.organization import Organization
45
from sentry.models.release import Release
56
from sentry.models.releasecommit import ReleaseCommit
7+
from sentry.organizations.services.organization import RpcOrganization
68

79

8-
def get_group_ids_resolved_in_release(organization, version):
10+
def get_group_ids_resolved_in_release(
11+
organization: Organization | RpcOrganization, version: str
12+
) -> set[int]:
913
try:
1014
release = Release.objects.get(version=version, organization=organization)
1115
except Release.DoesNotExist:

src/sentry/api/helpers/slugs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def validate_sentry_slug(slug: str) -> None:
2020
validator(slug)
2121

2222

23-
def sentry_slugify(slug: str, allow_unicode=False) -> str:
23+
def sentry_slugify(slug: str, allow_unicode: bool = False) -> str:
2424
"""
2525
Slugify a string using Django's built-in slugify function. Ensures that the
2626
slug is not entirely numeric by adding 3 letter suffix if necessary.

0 commit comments

Comments
 (0)