Browse Source

ref: Remove typing_extensions dep (#29521)

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
Markus Unterwaditzer 3 years ago
parent
commit
a9b85de35e

+ 0 - 4
requirements-base.txt

@@ -91,7 +91,3 @@ phabricator==0.7.0
 # sentry.utils.pytest and sentry.testutils are moved to tests/
 selenium==3.141.0
 sqlparse==0.2.4
-
-# this is already a transitive dependency via structlog, and we started
-# implicitly relying on it because of that. Can probably be removed with 3.8
-typing-extensions==3.10.0.2

+ 25 - 29
src/sentry/grouping/strategies/base.py

@@ -1,6 +1,5 @@
 import inspect
 from typing import (
-    TYPE_CHECKING,
     Any,
     Callable,
     Dict,
@@ -8,6 +7,7 @@ from typing import (
     Iterator,
     List,
     Optional,
+    Protocol,
     Sequence,
     Type,
     TypeVar,
@@ -40,34 +40,30 @@ DEFAULT_GROUPING_ENHANCEMENTS_BASE = "common:2019-03-23"
 ReturnedVariants = Dict[str, GroupingComponent]
 ConcreteInterface = TypeVar("ConcreteInterface", bound=Interface, contravariant=True)
 
-# TODO(3.8): This is a hack so we can get Protocols before 3.8
-if TYPE_CHECKING:
-    from typing_extensions import Protocol
-
-    # XXX(markus): Too hard to mock out Protocol at runtime for as long as
-    # we're not on 3.8, so let's just conditionally define all of our types.
-    class StrategyFunc(Protocol[ConcreteInterface]):
-        def __call__(
-            self,
-            interface: ConcreteInterface,
-            event: Event,
-            context: "GroupingContext",
-            **meta: Any,
-        ) -> ReturnedVariants:
-            ...
-
-    class VariantProcessor(Protocol):
-        def __call__(
-            self, variants: ReturnedVariants, context: "GroupingContext", **meta: Any
-        ) -> ReturnedVariants:
-            ...
+
+class StrategyFunc(Protocol[ConcreteInterface]):
+    def __call__(
+        self,
+        interface: ConcreteInterface,
+        event: Event,
+        context: "GroupingContext",
+        **meta: Any,
+    ) -> ReturnedVariants:
+        ...
+
+
+class VariantProcessor(Protocol):
+    def __call__(
+        self, variants: ReturnedVariants, context: "GroupingContext", **meta: Any
+    ) -> ReturnedVariants:
+        ...
 
 
 def strategy(
     ids: Sequence[str],
     interface: Type[Interface],
     score: Optional[int] = None,
-) -> Callable[["StrategyFunc[ConcreteInterface]"], "Strategy[ConcreteInterface]"]:
+) -> Callable[[StrategyFunc[ConcreteInterface]], "Strategy[ConcreteInterface]"]:
     """
     Registers a strategy
 
@@ -83,7 +79,7 @@ def strategy(
     if not ids:
         raise TypeError("no ids given")
 
-    def decorator(f: "StrategyFunc[ConcreteInterface]") -> Strategy[ConcreteInterface]:
+    def decorator(f: StrategyFunc[ConcreteInterface]) -> Strategy[ConcreteInterface]:
         rv: Optional[Strategy[ConcreteInterface]] = None
 
         for id in ids:
@@ -169,7 +165,7 @@ class Strategy(Generic[ConcreteInterface]):
         name: str,
         interface: str,
         score: Optional[int],
-        func: "StrategyFunc[ConcreteInterface]",
+        func: StrategyFunc[ConcreteInterface],
     ):
         self.id = id
         self.strategy_class = id.split(":", 1)[0]
@@ -177,7 +173,7 @@ class Strategy(Generic[ConcreteInterface]):
         self.interface = interface
         self.score = score
         self.func = func
-        self.variant_processor_func: Optional["VariantProcessor"] = None
+        self.variant_processor_func: Optional[VariantProcessor] = None
 
     def __repr__(self) -> str:
         return f"<{self.__class__.__name__} id={self.id!r}>"
@@ -194,7 +190,7 @@ class Strategy(Generic[ConcreteInterface]):
     def __call__(self, *args: Any, **kwargs: Any) -> ReturnedVariants:
         return self._invoke(self.func, *args, **kwargs)
 
-    def variant_processor(self, func: "VariantProcessor") -> "VariantProcessor":
+    def variant_processor(self, func: VariantProcessor) -> VariantProcessor:
         """Registers a variant reducer function that can be used to postprocess
         all variants created from this strategy.
         """
@@ -399,7 +395,7 @@ def create_strategy_configuration(
 
 def produces_variants(
     variants: Sequence[str],
-) -> Callable[["StrategyFunc[ConcreteInterface]"], "StrategyFunc[ConcreteInterface]"]:
+) -> Callable[[StrategyFunc[ConcreteInterface]], StrategyFunc[ConcreteInterface]]:
     """
     A grouping strategy can either:
 
@@ -429,7 +425,7 @@ def produces_variants(
         @produces_variants(["!system", "app"])
     """
 
-    def decorator(f: "StrategyFunc[ConcreteInterface]") -> "StrategyFunc[ConcreteInterface]":
+    def decorator(f: StrategyFunc[ConcreteInterface]) -> StrategyFunc[ConcreteInterface]:
         def inner(*args: Any, **kwargs: Any) -> ReturnedVariants:
             return call_with_variants(f, variants, *args, **kwargs)
 

+ 1 - 3
src/sentry/notifications/notifications/base.py

@@ -2,9 +2,7 @@ from __future__ import annotations
 
 import abc
 from dataclasses import dataclass
-from typing import TYPE_CHECKING, Any, Mapping, MutableMapping
-
-from typing_extensions import Literal
+from typing import TYPE_CHECKING, Any, Literal, Mapping, MutableMapping
 
 from sentry import analytics
 from sentry.types.integrations import ExternalProviders

+ 1 - 3
src/sentry/release_health/base.py

@@ -1,7 +1,5 @@
 from datetime import datetime
-from typing import Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union
-
-from typing_extensions import Literal, TypedDict
+from typing import Literal, Mapping, Optional, Sequence, Set, Tuple, TypedDict, TypeVar, Union
 
 from sentry.snuba.sessions_v2 import QueryDefinition
 from sentry.utils.services import Service

+ 2 - 1
src/sentry/release_health/metrics_sessions_v2.py

@@ -10,12 +10,14 @@ from typing import (
     Any,
     Generator,
     List,
+    Literal,
     Mapping,
     MutableMapping,
     Optional,
     Sequence,
     Set,
     Tuple,
+    TypedDict,
     Union,
     cast,
 )
@@ -25,7 +27,6 @@ from snuba_sdk.expressions import Granularity
 from snuba_sdk.function import Function
 from snuba_sdk.legacy import json_to_snql
 from snuba_sdk.query import SelectableExpression
-from typing_extensions import Literal, TypedDict
 
 from sentry.release_health.base import (
     GroupByFieldName,

+ 4 - 8
src/sentry/reprocessing2.py

@@ -82,13 +82,9 @@ import logging
 import uuid
 from dataclasses import dataclass
 from datetime import datetime
-from typing import TYPE_CHECKING, Any, Dict, List, Tuple, Union
+from typing import Any, Dict, List, Literal, Tuple, Union
 
 import redis
-
-if TYPE_CHECKING:
-    from typing_extensions import Literal
-
 import sentry_sdk
 from django.conf import settings
 
@@ -128,11 +124,11 @@ EVENT_MODELS_TO_MIGRATE = (models.EventAttachment, models.UserReport)
 CannotReprocessReason = Union[
     # Can have many reasons. The event is too old to be reprocessed (very
     # unlikely!) or was not a native event.
-    "Literal['unprocessed_event.not_found']",
+    Literal["unprocessed_event.not_found"],
     # The event does not exist.
-    "Literal['event.not_found']",
+    Literal["event.not_found"],
     # A required attachment, such as the original minidump, is missing.
-    "Literal['attachment.not_found']",
+    Literal["attachment.not_found"],
 ]
 
 

+ 1 - 2
src/sentry/snuba/metrics.py

@@ -5,12 +5,11 @@ import re
 from abc import ABC, abstractmethod
 from collections import OrderedDict
 from datetime import datetime, timedelta
-from typing import List, Optional, Tuple, Union
+from typing import List, Optional, Protocol, Tuple, Union
 
 from snuba_sdk import And, Column, Condition, Entity, Granularity, Limit, Offset, Op, Or, Query
 from snuba_sdk.conditions import BooleanCondition
 from snuba_sdk.query import SelectableExpression
-from typing_extensions import Protocol
 
 from sentry.models import Project
 from sentry.sentry_metrics import indexer

+ 1 - 1
src/sentry/tasks/low_priority_symbolication.py

@@ -10,9 +10,9 @@ This has three major tasks, executed in the following general order:
 
 import logging
 import time
+from typing import Literal
 
 import sentry_sdk
-from typing_extensions import Literal
 
 from sentry import options
 from sentry.killswitches import normalize_value