Skip to content

Commit db570af

Browse files
authored
chore(grouping): Use types rather than strings in type hints (#87751)
Pre-commit wants the string types in `strategies/base.py` and `enhancers/matchers.py` to be real types. Pulling this into a separate PR so as not to pollute an unrelated PR that happens to touch these files.
1 parent 18597c6 commit db570af

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/sentry/grouping/enhancer/matchers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from collections.abc import Callable
24
from typing import Any, Literal, Self, TypedDict
35

@@ -160,7 +162,7 @@ def _to_config_structure(self, version: int) -> str:
160162
raise NotImplementedError()
161163

162164
@staticmethod
163-
def _from_config_structure(config_structure: str, version: int) -> "EnhancementMatch":
165+
def _from_config_structure(config_structure: str, version: int) -> EnhancementMatch:
164166
val = config_structure
165167
if val.startswith("|[") and val.endswith("]"):
166168
frame_match: Any = EnhancementMatch._from_config_structure(val[2:-1], version)

src/sentry/grouping/strategies/base.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import inspect
24
from collections.abc import Callable, Iterator, Sequence
35
from typing import Any, Generic, Protocol, Self, TypeVar, overload
@@ -15,7 +17,7 @@
1517
from sentry.interfaces.exception import SingleException
1618
from sentry.interfaces.stacktrace import Frame, Stacktrace
1719

18-
STRATEGIES: dict[str, "Strategy[Any]"] = {}
20+
STRATEGIES: dict[str, Strategy[Any]] = {}
1921

2022
RISK_LEVEL_LOW = 0
2123
RISK_LEVEL_MEDIUM = 1
@@ -43,22 +45,22 @@ def __call__(
4345
self,
4446
interface: ConcreteInterface,
4547
event: Event,
46-
context: "GroupingContext",
48+
context: GroupingContext,
4749
**meta: Any,
4850
) -> ReturnedVariants: ...
4951

5052

5153
class VariantProcessor(Protocol):
5254
def __call__(
53-
self, variants: ReturnedVariants, context: "GroupingContext", **meta: Any
55+
self, variants: ReturnedVariants, context: GroupingContext, **meta: Any
5456
) -> ReturnedVariants: ...
5557

5658

5759
def strategy(
5860
ids: Sequence[str],
5961
interface: type[Interface],
6062
score: int | None = None,
61-
) -> Callable[[StrategyFunc[ConcreteInterface]], "Strategy[ConcreteInterface]"]:
63+
) -> Callable[[StrategyFunc[ConcreteInterface]], Strategy[ConcreteInterface]]:
6264
"""
6365
Registers a strategy
6466
@@ -89,7 +91,7 @@ def decorator(f: StrategyFunc[ConcreteInterface]) -> Strategy[ConcreteInterface]
8991

9092

9193
class GroupingContext:
92-
def __init__(self, strategy_config: "StrategyConfiguration"):
94+
def __init__(self, strategy_config: StrategyConfiguration):
9395
# The initial context is essentially the grouping config options
9496
self._stack = [strategy_config.initial_context]
9597
self.config = strategy_config
@@ -169,7 +171,7 @@ def _get_strategy_dict(
169171
return rv
170172

171173

172-
def lookup_strategy(strategy_id: str) -> "Strategy[Any]":
174+
def lookup_strategy(strategy_id: str) -> Strategy[Any]:
173175
"""Looks up a strategy by id."""
174176
try:
175177
return STRATEGIES[strategy_id]
@@ -286,7 +288,7 @@ def get_grouping_components(self, event: Event, context: GroupingContext) -> Ret
286288

287289
class StrategyConfiguration:
288290
id: str | None
289-
base: type["StrategyConfiguration"] | None = None
291+
base: type[StrategyConfiguration] | None = None
290292
config_class = None
291293
strategies: dict[str, Strategy[Any]] = {}
292294
delegates: dict[str, Strategy[Any]] = {}

0 commit comments

Comments
 (0)