Browse Source

ref: forbid 'Unpacking a string is disallowed' mypy error in ignored files (#75365)

slight improvement to typing-ignored `sentry.eventstore.models`

<!-- Describe your PR here. -->
anthony sottile 7 months ago
parent
commit
bd524218d6
2 changed files with 16 additions and 7 deletions
  1. 1 0
      .github/workflows/backend.yml
  2. 15 7
      src/sentry/eventstore/models.py

+ 1 - 0
.github/workflows/backend.yml

@@ -333,6 +333,7 @@ jobs:
           ! grep 'Incompatible return value type (got "HttpResponseBase"' .artifacts/mypy-all
           ! grep 'Incompatible types in "yield"' .artifacts/mypy-all
           ! grep 'Module "sentry.*has no attribute' .artifacts/mypy-all
+          ! grep 'Unpacking a string is disallowed' .artifacts/mypy-all
           ! grep 'base class .* defined the type as.*Permission' .artifacts/mypy-all
           ! grep 'does not explicitly export attribute' .artifacts/mypy-all
 

+ 15 - 7
src/sentry/eventstore/models.py

@@ -7,7 +7,7 @@ from collections.abc import Mapping, MutableMapping, Sequence
 from copy import deepcopy
 from datetime import datetime, timezone
 from hashlib import md5
-from typing import TYPE_CHECKING, Any, Optional, cast
+from typing import TYPE_CHECKING, Any, Literal, Optional, cast, overload
 
 import orjson
 import sentry_sdk
@@ -305,6 +305,14 @@ class BaseEvent(metaclass=abc.ABCMeta):
     def interfaces(self) -> Mapping[str, Interface]:
         return get_interfaces(self.data)
 
+    @overload
+    def get_interface(self, name: Literal["user"]) -> User:
+        ...
+
+    @overload
+    def get_interface(self, name: str) -> Interface | None:
+        ...
+
     def get_interface(self, name: str) -> Interface | None:
         return self.interfaces.get(name)
 
@@ -376,12 +384,12 @@ class BaseEvent(metaclass=abc.ABCMeta):
         if hierarchical_hashes:
             sentry_sdk.set_tag("get_hashes.hierarchical_variant", hierarchical_hashes[0][0])
 
-        flat_hashes = [hash_ for _, hash_ in flat_hashes]
-        hierarchical_hashes = [hash_ for _, hash_ in hierarchical_hashes]
+        flat_hashes_values = [hash_ for _, hash_ in flat_hashes]
+        hierarchical_hashes_values = [hash_ for _, hash_ in hierarchical_hashes]
 
         return CalculatedHashes(
-            hashes=flat_hashes,
-            hierarchical_hashes=hierarchical_hashes,
+            hashes=flat_hashes_values,
+            hierarchical_hashes=hierarchical_hashes_values,
             tree_labels=tree_labels,
             variants=variants,
         )
@@ -389,7 +397,7 @@ class BaseEvent(metaclass=abc.ABCMeta):
     @staticmethod
     def _hashes_from_sorted_grouping_variants(
         variants: KeyedVariants,
-    ) -> tuple[list[str], list[Any]]:
+    ) -> tuple[list[tuple[str, str]], list[Any]]:
         """Create hashes from variants and filter out duplicates and None values"""
 
         from sentry.grouping.variants import ComponentVariant
@@ -449,7 +457,7 @@ class BaseEvent(metaclass=abc.ABCMeta):
             if isinstance(force_config, str):
                 # A string like `"mobile:2021-02-12"`
                 stored_config = self.get_grouping_config()
-                grouping_config = dict(stored_config)
+                grouping_config = stored_config.copy()
                 grouping_config["id"] = force_config
                 loaded_grouping_config = load_grouping_config(grouping_config)
             elif isinstance(force_config, StrategyConfiguration):