Browse Source

ref: annotate difcache as a ClassVar (#51609)

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

+ 0 - 4
pyproject.toml

@@ -446,7 +446,6 @@ module = [
     "sentry.auth.superuser",
     "sentry.auth.system",
     "sentry.auth.view",
-    "sentry.bgtasks.clean_dsymcache",
     "sentry.bgtasks.clean_releasefilecache",
     "sentry.buffer.redis",
     "sentry.cache",
@@ -655,9 +654,7 @@ module = [
     "sentry.issues.occurrence_consumer",
     "sentry.issues.search",
     "sentry.issues.status_change",
-    "sentry.lang.dart.utils",
     "sentry.lang.java.plugin",
-    "sentry.lang.java.utils",
     "sentry.lang.javascript.errorlocale",
     "sentry.lang.javascript.errormapping",
     "sentry.lang.javascript.processor",
@@ -1448,7 +1445,6 @@ module = [
     "tests.sentry.models.test_activity",
     "tests.sentry.models.test_authenticator",
     "tests.sentry.models.test_avatar",
-    "tests.sentry.models.test_debugfile",
     "tests.sentry.models.test_eventuser",
     "tests.sentry.models.test_groupassignee",
     "tests.sentry.models.test_grouphistory",

+ 5 - 3
src/sentry/lang/dart/utils.py

@@ -1,9 +1,11 @@
+from __future__ import annotations
+
 import os
 import re
+from typing import Any
 
 import sentry_sdk
 
-from sentry.eventstore.models import Event
 from sentry.lang.java.utils import deobfuscation_template
 from sentry.models import Project, ProjectDebugFile
 from sentry.utils import json
@@ -28,7 +30,7 @@ def has_dart_symbols_file(data):
     return get_path(images, 0, "type") == "dart_symbols"
 
 
-def get_dart_symbols_images(event: Event):
+def get_dart_symbols_images(event: dict[str, Any]) -> set[str]:
     return {
         str(image["uuid"]).lower()
         for image in get_path(event, "debug_meta", "images", filter=is_valid_image, default=())
@@ -72,7 +74,7 @@ def generate_dart_symbols_map(uuid: str, project: Project):
     return obfuscated_to_deobfuscated_name_map
 
 
-def _deobfuscate_view_hierarchy(event_data: Event, project: Project, view_hierarchy):
+def _deobfuscate_view_hierarchy(event_data: dict[str, Any], project: Project, view_hierarchy):
     """
     Deobfuscates a view hierarchy in-place.
 

+ 6 - 4
src/sentry/lang/java/utils.py

@@ -1,10 +1,12 @@
+from __future__ import annotations
+
 import os
+from typing import Any
 
 import sentry_sdk
 from symbolic import ProguardMapper
 
 from sentry.attachments import CachedAttachment, attachment_cache
-from sentry.eventstore.models import Event
 from sentry.ingest.ingest_consumer import CACHE_TIMEOUT
 from sentry.models import Project, ProjectDebugFile
 from sentry.utils import json
@@ -28,7 +30,7 @@ def has_proguard_file(data):
     return get_path(images, 0, "type") == "proguard"
 
 
-def get_proguard_images(event: Event):
+def get_proguard_images(event: dict[str, Any]) -> set[str]:
     images = set()
     for image in get_path(
         event, "debug_meta", "images", filter=is_valid_proguard_image, default=()
@@ -37,7 +39,7 @@ def get_proguard_images(event: Event):
     return images
 
 
-def get_jvm_images(event: Event):
+def get_jvm_images(event: dict[str, Any]) -> set[str]:
     images = set()
     for image in get_path(event, "debug_meta", "images", filter=is_valid_jvm_image, default=()):
         images.add(str(image["debug_id"]).lower())
@@ -67,7 +69,7 @@ def get_proguard_mapper(uuid: str, project: Project):
     return mapper
 
 
-def _deobfuscate_view_hierarchy(event_data: Event, project: Project, view_hierarchy):
+def _deobfuscate_view_hierarchy(event_data: dict[str, Any], project: Project, view_hierarchy):
     """
     Deobfuscates a view hierarchy in-place.
 

+ 7 - 4
src/sentry/models/debugfile.py

@@ -15,6 +15,7 @@ from typing import (
     TYPE_CHECKING,
     Any,
     BinaryIO,
+    ClassVar,
     Dict,
     FrozenSet,
     Iterable,
@@ -82,7 +83,7 @@ class ProjectDebugFileManager(BaseManager):
         return sorted(missing)
 
     def find_by_debug_ids(
-        self, project: Project, debug_ids: List[str], features: Optional[Set[str]] = None
+        self, project: Project, debug_ids: List[str], features: Iterable[str] | None = None
     ) -> Dict[str, ProjectDebugFile]:
         """Finds debug information files matching the given debug identifiers.
 
@@ -92,7 +93,7 @@ class ProjectDebugFileManager(BaseManager):
 
         Returns a dict of debug files keyed by their debug identifier.
         """
-        features: FrozenSet[str] = frozenset(features) if features is not None else frozenset()  # type: ignore
+        features = frozenset(features) if features is not None else frozenset()
 
         difs = (
             ProjectDebugFile.objects.filter(project_id=project.id, debug_id__in=debug_ids)
@@ -140,6 +141,8 @@ class ProjectDebugFile(Model):
     data = JSONField(null=True)
     objects = ProjectDebugFileManager()
 
+    difcache: ClassVar[DIFCache]
+
     class Meta:
         index_together = (("project_id", "debug_id"), ("project_id", "code_id"))
         db_table = "sentry_projectdsymfile"
@@ -604,7 +607,7 @@ class DIFCache:
         return os.path.join(self.cache_path, str(project.id))
 
     def fetch_difs(
-        self, project: Project, debug_ids: Iterable[str], features: Optional[Set[str]] = None
+        self, project: Project, debug_ids: Iterable[str], features: Iterable[str] | None = None
     ) -> Mapping[str, str]:
         """Given some ids returns an id to path mapping for where the
         debug symbol files are on the FS.
@@ -629,4 +632,4 @@ class DIFCache:
         clear_cached_files(self.cache_path)
 
 
-ProjectDebugFile.difcache = DIFCache()  # type: ignore[attr-defined]
+ProjectDebugFile.difcache = DIFCache()

+ 4 - 1
tests/sentry/models/test_debugfile.py

@@ -1,7 +1,10 @@
+from __future__ import annotations
+
 import os
 import time
 import zipfile
 from io import BytesIO
+from typing import Any
 
 from django.core.files.uploadedfile import SimpleUploadedFile
 from django.urls import reverse
@@ -117,7 +120,7 @@ class CreateDebugFileTest(APITestCase):
         return os.path.join(os.path.dirname(__file__), "fixtures", "crash.dsym")
 
     def create_dif(self, fileobj=None, file=None, **kwargs):
-        args = {
+        args: dict[str, Any] = {
             "file_format": "macho",
             "arch": "x86_64",
             "debug_id": "67e9247c-814e-392b-a027-dbde6748fcbf",