Browse Source

ref: fix some mypy issues (#52990)

<!-- Describe your PR here. -->
anthony sottile 1 year ago
parent
commit
165ffad930

+ 0 - 38
pyproject.toml

@@ -430,8 +430,6 @@ module = [
     "sentry.db.postgres.decorators",
     "sentry.db.postgres.operations",
     "sentry.db.router",
-    "sentry.debug.utils.packages",
-    "sentry.debug.utils.thread_collector",
     "sentry.deletions.defaults.group",
     "sentry.deletions.defaults.project",
     "sentry.digests.notifications",
@@ -679,7 +677,6 @@ module = [
     "sentry.models.integrations.sentry_app_installation_token",
     "sentry.models.notificationaction",
     "sentry.models.notificationsetting",
-    "sentry.models.options.organization_option",
     "sentry.models.options.project_option",
     "sentry.models.options.user_option",
     "sentry.models.organization",
@@ -837,7 +834,6 @@ module = [
     "sentry.shared_integrations.client.internal",
     "sentry.shared_integrations.client.proxy",
     "sentry.silo.base",
-    "sentry.silo.client",
     "sentry.similarity.backends.dummy",
     "sentry.similarity.features",
     "sentry.snuba.discover",
@@ -1024,12 +1020,6 @@ module = [
     "sentry_plugins.splunk.plugin",
     "sentry_plugins.trello.plugin",
     "sentry_plugins.twilio.plugin",
-    "tests.acceptance.chartcuterie.test_chart_renderer",
-    "tests.acceptance.test_organization_dashboards",
-    "tests.acceptance.test_shared_issue",
-    "tests.integration.test_api",
-    "tests.relay_integration.lang.java.test_plugin",
-    "tests.relay_integration.test_sdk",
     "tests.sentry.api.bases.test_organization",
     "tests.sentry.api.bases.test_project",
     "tests.sentry.api.bases.test_sentryapps",
@@ -1063,19 +1053,15 @@ module = [
     "tests.sentry.api.endpoints.test_organization_metric_tag_details",
     "tests.sentry.api.endpoints.test_organization_metrics",
     "tests.sentry.api.endpoints.test_organization_recent_searches",
-    "tests.sentry.api.endpoints.test_organization_release_file_details",
     "tests.sentry.api.endpoints.test_organization_releases",
-    "tests.sentry.api.endpoints.test_organization_repository_details",
     "tests.sentry.api.endpoints.test_organization_sdk_updates",
     "tests.sentry.api.endpoints.test_organization_sentry_app_installation_details",
     "tests.sentry.api.endpoints.test_organization_sentry_functions",
-    "tests.sentry.api.endpoints.test_project_artifact_bundle_file_details",
     "tests.sentry.api.endpoints.test_project_artifact_lookup",
     "tests.sentry.api.endpoints.test_project_details",
     "tests.sentry.api.endpoints.test_project_group_stats",
     "tests.sentry.api.endpoints.test_project_ownership",
     "tests.sentry.api.endpoints.test_project_release_details",
-    "tests.sentry.api.endpoints.test_project_release_file_details",
     "tests.sentry.api.endpoints.test_project_releases",
     "tests.sentry.api.endpoints.test_project_rule_details",
     "tests.sentry.api.endpoints.test_project_rules",
@@ -1093,8 +1079,6 @@ module = [
     "tests.sentry.api.endpoints.test_team_alerts_triggered",
     "tests.sentry.api.endpoints.test_team_details",
     "tests.sentry.api.endpoints.test_user_authenticator_details",
-    "tests.sentry.api.endpoints.test_user_details",
-    "tests.sentry.api.endpoints.test_user_notification_fine_tuning",
     "tests.sentry.api.endpoints.test_user_permission_details",
     "tests.sentry.api.endpoints.test_user_role_details",
     "tests.sentry.api.endpoints.test_user_roles",
@@ -1124,19 +1108,16 @@ module = [
     "tests.sentry.api.validators.sentry_apps.test_select",
     "tests.sentry.api.validators.sentry_apps.test_text",
     "tests.sentry.api.validators.sentry_apps.test_textarea",
-    "tests.sentry.api_gateway.test_api_gateway",
     "tests.sentry.apidocs.test_extensions",
     "tests.sentry.auth.authenticators.test_sms",
     "tests.sentry.auth.authenticators.test_u2f",
     "tests.sentry.auth.providers.test_saml2",
     "tests.sentry.auth.test_access",
     "tests.sentry.auth.test_helper",
-    "tests.sentry.charts.test_chartcuterie",
     "tests.sentry.data_export.endpoints.test_data_export",
     "tests.sentry.db.models.fields.test_jsonfield",
     "tests.sentry.db.models.fields.test_picklefield",
     "tests.sentry.db.postgres.schema.safe_migrations.integration.test_migrations",
-    "tests.sentry.db.test_mixin",
     "tests.sentry.db.test_silo_models",
     "tests.sentry.deletions.test_group",
     "tests.sentry.deletions.test_project",
@@ -1281,22 +1262,11 @@ module = [
     "tests.sentry.middleware.test_stats",
     "tests.sentry.middleware.test_subdomain",
     "tests.sentry.middleware.test_useractive",
-    "tests.sentry.models.test_activity",
-    "tests.sentry.models.test_authenticator",
-    "tests.sentry.models.test_avatar",
-    "tests.sentry.models.test_eventuser",
-    "tests.sentry.models.test_grouphistory",
-    "tests.sentry.models.test_groupsnooze",
     "tests.sentry.models.test_notificationaction",
     "tests.sentry.models.test_notificationsetting",
     "tests.sentry.models.test_organization",
     "tests.sentry.models.test_organizationmember",
-    "tests.sentry.models.test_organizationoption",
     "tests.sentry.models.test_project",
-    "tests.sentry.models.test_projectownership",
-    "tests.sentry.models.test_release",
-    "tests.sentry.models.test_releasefile",
-    "tests.sentry.models.test_sentryapp",
     "tests.sentry.monitors.endpoints.test_monitor_ingest_checkin_details",
     "tests.sentry.monitors.test_models",
     "tests.sentry.nodestore.bigtable.test_backend",
@@ -1358,8 +1328,6 @@ module = [
     "tests.sentry.sentry_metrics.test_strings",
     "tests.sentry.services.test_http",
     "tests.sentry.shared_integrations.client.test_base",
-    "tests.sentry.silo.test_client",
-    "tests.sentry.silo.test_util",
     "tests.sentry.snuba.metrics.fields.test_base",
     "tests.sentry.snuba.metrics.test_metrics_layer.test_metrics_enhanced_performance",
     "tests.sentry.snuba.metrics.test_metrics_layer.test_release_health",
@@ -1388,7 +1356,6 @@ module = [
     "tests.sentry.tasks.test_servicehooks",
     "tests.sentry.tasks.test_store",
     "tests.sentry.templatetags.test_sentry_assets",
-    "tests.sentry.test_constants",
     "tests.sentry.test_killswitches",
     "tests.sentry.test_stacktraces",
     "tests.sentry.testutils.helpers.test_features",
@@ -1405,7 +1372,6 @@ module = [
     "tests.sentry.utils.test_safe",
     "tests.sentry.utils.test_services",
     "tests.sentry.utils.test_time_window",
-    "tests.sentry.web.frontend.generic.test_static_media",
     "tests.sentry.web.frontend.test_auth_login",
     "tests.sentry.web.frontend.test_auth_oauth2",
     "tests.sentry.web.frontend.test_auth_organization_login",
@@ -1460,10 +1426,6 @@ module = [
     "tests.snuba.tasks.test_unmerge",
     "tests.snuba.test_util",
     "tests.snuba.tsdb.test_tsdb_backend",
-    "tests.symbolicator",
-    "tests.symbolicator.test_minidump_full",
-    "tests.symbolicator.test_payload_full",
-    "tests.symbolicator.test_unreal_full",
 ]
 disable_error_code = [
     "arg-type",

+ 1 - 4
src/sentry/debug/utils/packages.py

@@ -1,9 +1,6 @@
 import sys
 
-try:
-    import pkg_resources
-except ImportError:
-    pkg_resources = None
+import pkg_resources
 
 
 def get_package_version(module_name, app):

+ 0 - 34
src/sentry/debug/utils/thread_collector.py

@@ -1,34 +0,0 @@
-import threading
-import weakref
-
-
-class ThreadCollector:
-    def __init__(self):
-        self.collections = weakref.WeakKeyDictionary()
-
-    def enable(self, thread=None):
-        if thread is None:
-            thread = threading.currentThread()
-        self.collections[thread] = []
-        return self.collections[thread]
-
-    def disable(self, thread=None):
-        if thread is None:
-            thread = threading.currentThread()
-        try:
-            del self.collections[thread]
-        except KeyError:
-            pass
-
-    def get(self, thread=None):
-        if thread is None:
-            thread = threading.currentThread()
-        return self.collections[thread]
-
-    def append(self, item, thread=None):
-        if thread is None:
-            thread = threading.currentThread()
-        # fail silently if not active for thread
-        if thread not in self.collections:
-            return
-        self.collections[thread].append(item)

+ 6 - 2
src/sentry/models/avatars/doc_integration_avatar.py

@@ -1,3 +1,7 @@
+from __future__ import annotations
+
+from typing import ClassVar
+
 from django.db import models
 from django.utils import timezone
 
@@ -12,9 +16,9 @@ class DocIntegrationAvatar(ControlAvatarBase):
     A DocIntegrationAvatar associates a DocIntegration with a logo photo File.
     """
 
-    AVATAR_TYPES = ((0, "upload"),)
+    AVATAR_TYPES: ClassVar[tuple[tuple[int, str], ...]] = ((0, "upload"),)
 
-    FILE_TYPE = "avatar.file"
+    FILE_TYPE: ClassVar[str] = "avatar.file"
 
     doc_integration = FlexibleForeignKey("sentry.DocIntegration", related_name="avatar")
     avatar_type = models.PositiveSmallIntegerField(default=0, choices=((0, "upload"),))

+ 6 - 2
src/sentry/models/avatars/organization_avatar.py

@@ -1,3 +1,7 @@
+from __future__ import annotations
+
+from typing import ClassVar
+
 from django.db import models
 
 from sentry.db.models import FlexibleForeignKey, region_silo_only_model
@@ -12,9 +16,9 @@ class OrganizationAvatar(AvatarBase):
     and contains their preferences for avatar type.
     """
 
-    AVATAR_TYPES = ((0, "letter_avatar"), (1, "upload"))
+    AVATAR_TYPES: ClassVar[tuple[tuple[int, str], ...]] = ((0, "letter_avatar"), (1, "upload"))
 
-    FILE_TYPE = "avatar.file"
+    FILE_TYPE: ClassVar[str] = "avatar.file"
 
     organization = FlexibleForeignKey("sentry.Organization", unique=True, related_name="avatar")
     avatar_type = models.PositiveSmallIntegerField(default=0, choices=AVATAR_TYPES)

+ 6 - 2
src/sentry/models/avatars/project_avatar.py

@@ -1,3 +1,7 @@
+from __future__ import annotations
+
+from typing import ClassVar
+
 from django.db import models
 
 from sentry.db.models import FlexibleForeignKey, region_silo_only_model
@@ -12,9 +16,9 @@ class ProjectAvatar(AvatarBase):
     and contains their preferences for avatar type.
     """
 
-    AVATAR_TYPES = ((0, "letter_avatar"), (1, "upload"))
+    AVATAR_TYPES: ClassVar[tuple[tuple[int, str], ...]] = ((0, "letter_avatar"), (1, "upload"))
 
-    FILE_TYPE = "avatar.file"
+    FILE_TYPE: ClassVar[str] = "avatar.file"
 
     project = FlexibleForeignKey("sentry.Project", unique=True, related_name="avatar")
     avatar_type = models.PositiveSmallIntegerField(default=0, choices=AVATAR_TYPES)

+ 2 - 2
src/sentry/models/avatars/sentry_app_avatar.py

@@ -2,7 +2,7 @@ from __future__ import annotations
 
 from collections import defaultdict
 from enum import Enum
-from typing import TYPE_CHECKING, List
+from typing import TYPE_CHECKING, ClassVar, List
 
 from django.db import models
 
@@ -47,7 +47,7 @@ class SentryAppAvatar(ControlAvatarBase):
 
     AVATAR_TYPES = SentryAppAvatarTypes.get_choices()
 
-    FILE_TYPE = "avatar.file"
+    FILE_TYPE: ClassVar[str] = "avatar.file"
 
     sentry_app = FlexibleForeignKey("sentry.SentryApp", related_name="avatar")
     avatar_type = models.PositiveSmallIntegerField(default=0, choices=AVATAR_TYPES)

+ 6 - 2
src/sentry/models/avatars/team_avatar.py

@@ -1,3 +1,7 @@
+from __future__ import annotations
+
+from typing import ClassVar
+
 from django.db import models
 
 from sentry.db.models import FlexibleForeignKey, region_silo_only_model
@@ -12,9 +16,9 @@ class TeamAvatar(AvatarBase):
     and contains their preferences for avatar type.
     """
 
-    AVATAR_TYPES = ((0, "letter_avatar"), (1, "upload"))
+    AVATAR_TYPES: ClassVar[tuple[tuple[int, str], ...]] = ((0, "letter_avatar"), (1, "upload"))
 
-    FILE_TYPE = "avatar.file"
+    FILE_TYPE: ClassVar[str] = "avatar.file"
 
     team = FlexibleForeignKey("sentry.Team", unique=True, related_name="avatar")
     avatar_type = models.PositiveSmallIntegerField(default=0, choices=AVATAR_TYPES)

+ 10 - 2
src/sentry/models/avatars/user_avatar.py

@@ -1,3 +1,7 @@
+from __future__ import annotations
+
+from typing import ClassVar
+
 from django.db import models
 
 from sentry.db.models import BaseManager, FlexibleForeignKey, control_silo_only_model
@@ -12,9 +16,13 @@ class UserAvatar(ControlAvatarBase):
     and contains their preferences for avatar type.
     """
 
-    AVATAR_TYPES = ((0, "letter_avatar"), (1, "upload"), (2, "gravatar"))
+    AVATAR_TYPES: ClassVar[tuple[tuple[int, str], ...]] = (
+        (0, "letter_avatar"),
+        (1, "upload"),
+        (2, "gravatar"),
+    )
 
-    FILE_TYPE = "avatar.file"
+    FILE_TYPE: ClassVar[str] = "avatar.file"
 
     user = FlexibleForeignKey("sentry.User", unique=True, related_name="avatar")
     avatar_type = models.PositiveSmallIntegerField(default=0, choices=AVATAR_TYPES)

+ 5 - 1
src/sentry/models/dashboard_widget.py

@@ -1,3 +1,7 @@
+from __future__ import annotations
+
+from typing import Any
+
 from django.contrib.postgres.fields import ArrayField as DjangoArrayField
 from django.db import models
 from django.utils import timezone
@@ -123,7 +127,7 @@ class DashboardWidget(Model):
     date_added = models.DateTimeField(default=timezone.now)
     widget_type = BoundedPositiveIntegerField(choices=DashboardWidgetTypes.as_choices(), null=True)
     limit = models.IntegerField(null=True)
-    detail = JSONField(null=True)
+    detail: models.Field[dict[str, Any], dict[str, Any]] = JSONField(null=True)
 
     class Meta:
         app_label = "sentry"

Some files were not shown because too many files changed in this diff