diff --git a/pyproject.toml b/pyproject.toml index e9ea7416f5289..d3a83cffa0497 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -338,19 +338,15 @@ module = [ "sentry.api.permissions", "sentry.api.serializers.models", "sentry.api.serializers.models.alert_rule", - "sentry.api.serializers.models.alert_rule_trigger", "sentry.api.serializers.models.auth_provider", "sentry.api.serializers.models.authenticator", - "sentry.api.serializers.models.commit", "sentry.api.serializers.models.dashboard", - "sentry.api.serializers.models.discoversavedquery", "sentry.api.serializers.models.doc_integration", "sentry.api.serializers.models.environment", "sentry.api.serializers.models.event", "sentry.api.serializers.models.external_actor", "sentry.api.serializers.models.group", "sentry.api.serializers.models.group_stream", - "sentry.api.serializers.models.grouprelease", "sentry.api.serializers.models.incident", "sentry.api.serializers.models.integration", "sentry.api.serializers.models.integration_feature", @@ -360,11 +356,9 @@ module = [ "sentry.api.serializers.models.plugin", "sentry.api.serializers.models.project", "sentry.api.serializers.models.projectcodeowners", - "sentry.api.serializers.models.release_file", "sentry.api.serializers.models.role", "sentry.api.serializers.models.rule", "sentry.api.serializers.models.sentry_app", - "sentry.api.serializers.models.tagvalue", "sentry.api.serializers.models.team", "sentry.api.serializers.models.user", "sentry.api.serializers.models.user_identity_config", diff --git a/src/sentry/api/serializers/models/alert_rule_trigger.py b/src/sentry/api/serializers/models/alert_rule_trigger.py index 13f54f2cce7a7..f1a2e7b463cee 100644 --- a/src/sentry/api/serializers/models/alert_rule_trigger.py +++ b/src/sentry/api/serializers/models/alert_rule_trigger.py @@ -1,4 +1,5 @@ from collections import defaultdict +from typing import DefaultDict, Dict, List from django.db.models import prefetch_related_objects @@ -17,7 +18,7 @@ def get_attrs(self, item_list, user, **kwargs): prefetch_related_objects(item_list, "alert_rule") triggers = {item.id: item for item in item_list} - result = defaultdict(dict) + result: DefaultDict[str, Dict[str, List[str]]] = defaultdict(dict) actions = AlertRuleTriggerAction.objects.filter(alert_rule_trigger__in=item_list).order_by( "id" @@ -49,7 +50,7 @@ def serialize(self, obj, attrs, user, **kwargs): class DetailedAlertRuleTriggerSerializer(AlertRuleTriggerSerializer): def get_attrs(self, item_list, user, **kwargs): triggers = {item.id: item for item in item_list} - result = defaultdict(dict) + result: DefaultDict[str, Dict[str, List[str]]] = defaultdict(dict) for trigger_id, project_slug in AlertRuleTriggerExclusion.objects.filter( alert_rule_trigger__in=item_list ).values_list("alert_rule_trigger_id", "query_subscription__project__slug"): diff --git a/src/sentry/api/serializers/models/commit.py b/src/sentry/api/serializers/models/commit.py index 7c0c4c8984e50..95cb089686c05 100644 --- a/src/sentry/api/serializers/models/commit.py +++ b/src/sentry/api/serializers/models/commit.py @@ -2,8 +2,8 @@ from typing import Mapping from sentry.api.serializers import Serializer, register, serialize -from sentry.api.serializers.models.release import Author, CommitAuthor, get_users_for_authors -from sentry.models import Commit, PullRequest, Repository +from sentry.api.serializers.models.release import Author, get_users_for_authors +from sentry.models import Commit, CommitAuthor, PullRequest, Repository def get_users_for_commits(item_list, user=None) -> Mapping[str, Author]: diff --git a/src/sentry/api/serializers/models/discoversavedquery.py b/src/sentry/api/serializers/models/discoversavedquery.py index bee64b903ad01..9554787897652 100644 --- a/src/sentry/api/serializers/models/discoversavedquery.py +++ b/src/sentry/api/serializers/models/discoversavedquery.py @@ -1,4 +1,5 @@ from collections import defaultdict +from typing import DefaultDict, Dict from sentry.api.serializers import Serializer, register from sentry.constants import ALL_ACCESS_PROJECTS @@ -10,7 +11,7 @@ @register(DiscoverSavedQuery) class DiscoverSavedQuerySerializer(Serializer): def get_attrs(self, item_list, user): - result = defaultdict(lambda: {"created_by": {}}) + result: DefaultDict[str, Dict] = defaultdict(lambda: {"created_by": {}}) service_serialized = user_service.serialize_many( filter={ diff --git a/src/sentry/api/serializers/models/grouprelease.py b/src/sentry/api/serializers/models/grouprelease.py index 04f8e86d938d5..682bcf00e43cd 100644 --- a/src/sentry/api/serializers/models/grouprelease.py +++ b/src/sentry/api/serializers/models/grouprelease.py @@ -1,5 +1,6 @@ from collections import namedtuple from datetime import timedelta +from typing import Dict, List from django.utils import timezone @@ -54,7 +55,7 @@ def get_attrs(self, item_list, user): else None ) - items = {} + items: Dict[str, List[str]] = {} for item in item_list: items.setdefault(item.group_id, []).append(item.id) attrs[item]["stats"] = {} @@ -64,7 +65,7 @@ def get_attrs(self, item_list, user): since = self.since or until - (segments * interval) try: - stats = tsdb.get_frequency_series( + stats = tsdb.backend.get_frequency_series( model=TSDBModel.frequent_releases_by_group, items=items, start=since, diff --git a/src/sentry/api/serializers/models/release_file.py b/src/sentry/api/serializers/models/release_file.py index 5c74978c44b05..bd19cea056898 100644 --- a/src/sentry/api/serializers/models/release_file.py +++ b/src/sentry/api/serializers/models/release_file.py @@ -29,8 +29,7 @@ def decode_release_file_id(id: str): except ValueError: decoded = urlsafe_b64decode(id).decode() dist, url = decoded.split("_", 1) - dist = dist or None - return dist, url + return dist or None, url @register(ReleaseFile) diff --git a/src/sentry/api/serializers/models/tagvalue.py b/src/sentry/api/serializers/models/tagvalue.py index 98baa55e90dee..c8cd05726b82a 100644 --- a/src/sentry/api/serializers/models/tagvalue.py +++ b/src/sentry/api/serializers/models/tagvalue.py @@ -1,3 +1,5 @@ +from typing import Any, Dict + from sentry.api.serializers import Serializer, serialize from sentry.models import EventUser from sentry.search.utils import convert_user_tag_to_query @@ -21,11 +23,9 @@ def get_attrs(self, item_list, user): return result def serialize(self, obj, attrs, user): - if not attrs["user"]: - result = {"id": None} - else: - result = serialize(attrs["user"], user) - + result: Dict[str, Any] = ( + {"id": None} if not attrs["user"] else serialize(attrs["user"], user) + ) query = convert_user_tag_to_query("user", obj.value) if query: result["query"] = query