Browse Source

ref: fix typing for similarity.features (#78844)

<!-- Describe your PR here. -->
anthony sottile 5 months ago
parent
commit
ced1d3edf5
2 changed files with 11 additions and 11 deletions
  1. 0 1
      pyproject.toml
  2. 11 10
      src/sentry/similarity/features.py

+ 0 - 1
pyproject.toml

@@ -326,7 +326,6 @@ module = [
     "sentry.sentry_apps.installations",
     "sentry.sentry_metrics.indexer.postgres.postgres_v2",
     "sentry.shared_integrations.client.proxy",
-    "sentry.similarity.features",
     "sentry.snuba.errors",
     "sentry.snuba.issue_platform",
     "sentry.snuba.metrics.datasource",

+ 11 - 10
src/sentry/similarity/features.py

@@ -1,4 +1,3 @@
-import functools
 import itertools
 import logging
 
@@ -66,10 +65,10 @@ class FeatureSet:
         self.expected_encoding_errors = expected_encoding_errors
         assert set(self.aliases) == set(self.features)
 
-    def __get_scope(self, project):
+    def __get_scope(self, project) -> str:
         return f"{project.id}"
 
-    def __get_key(self, group):
+    def __get_key(self, group) -> str:
         return f"{group.id}"
 
     def extract(self, event):
@@ -81,7 +80,7 @@ class FeatureSet:
                 log = (
                     logger.debug
                     if isinstance(error, self.expected_extraction_errors)
-                    else functools.partial(logger.warning, exc_info=True)
+                    else logger.warning
                 )
                 log(
                     "Could not extract features from %r for %r due to error: %r",
@@ -96,8 +95,8 @@ class FeatureSet:
         if not events:
             return []
 
-        scope = None
-        key = None
+        scope: str | None = None
+        key: str | None = None
 
         items = []
         for event in events:
@@ -124,13 +123,14 @@ class FeatureSet:
                     log = (
                         logger.debug
                         if isinstance(error, self.expected_encoding_errors)
-                        else functools.partial(logger.warning, exc_info=True)
+                        else logger.warning
                     )
                     log(
                         "Could not encode features from %r for %r due to error: %r",
                         event,
                         label,
                         error,
+                        exc_info=True,
                     )
                 else:
                     if features:
@@ -145,7 +145,7 @@ class FeatureSet:
         if thresholds is None:
             thresholds = {}
 
-        scope = None
+        scope: str | None = None
 
         labels = []
         items = []
@@ -164,13 +164,14 @@ class FeatureSet:
                     log = (
                         logger.debug
                         if isinstance(error, self.expected_encoding_errors)
-                        else functools.partial(logger.warning, exc_info=True)
+                        else logger.warning
                     )
                     log(
                         "Could not encode features from %r for %r due to error: %r",
                         event,
                         label,
                         error,
+                        exc_info=True,
                     )
                 else:
                     if features:
@@ -210,7 +211,7 @@ class FeatureSet:
         # within so that we can make the most efficient queries possible and
         # reject queries that cross scopes if we haven't explicitly allowed
         # unsafe actions.
-        scopes = {}
+        scopes: dict[str, set[str]] = {}
         for source in sources:
             scopes.setdefault(self.__get_scope(source.project), set()).add(source)