Skip to content

Commit

Permalink
ref: fix typing in a few files (#61422)
Browse files Browse the repository at this point in the history
<!-- Describe your PR here. -->
  • Loading branch information
asottile-sentry authored Dec 8, 2023
1 parent 00b84f0 commit a825290
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 30 deletions.
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/endpoints/group_hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get(self, request: Request, group) -> Response:

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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -66,7 +68,7 @@ def get(self, request: Request, organization) -> Response:
},
}
"""
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
Expand Down
12 changes: 6 additions & 6 deletions src/sentry/api/endpoints/organization_dashboards.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import re

from django.db import IntegrityError, router, transaction
Expand Down Expand Up @@ -67,14 +69,15 @@ def get(self, request: Request, organization) -> Response:
else:
desc = False

order_by: list[Case | str]
if sort_by == "title":
order_by = [
"-title" if desc else "title",
"-date_added",
]

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 = [
Expand All @@ -83,7 +86,7 @@ def get(self, request: Request, organization) -> Response:
]

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 = [
Expand All @@ -102,10 +105,7 @@ def get(self, request: Request, organization) -> Response:
]

else:
order_by = "title"

if not isinstance(order_by, list):
order_by = [order_by]
order_by = ["title"]

dashboards = dashboards.order_by(*order_by)

Expand Down
34 changes: 18 additions & 16 deletions src/sentry/rules/conditions/event_attribute.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Any, Dict, Sequence

from django import forms
Expand Down Expand Up @@ -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(".")

Expand Down Expand Up @@ -156,9 +158,9 @@ def _get_attribute_values(self, event: GroupEvent, attr: str) -> Sequence[str]:
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
Expand Down Expand Up @@ -218,7 +220,7 @@ def render_label(self) -> str:
}
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")

Expand All @@ -227,61 +229,61 @@ def _passes(self, attribute_values: Sequence[Any]) -> bool:

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")

Expand Down
13 changes: 12 additions & 1 deletion src/sentry/sdk_updates.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -143,7 +146,15 @@ def get_new_state(self, old_state):
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",
Expand Down

0 comments on commit a825290

Please sign in to comment.