1
1
from __future__ import annotations
2
2
3
3
from collections .abc import Callable , Sequence
4
- from typing import Any
4
+ from typing import TYPE_CHECKING , Any
5
5
6
+ from sentry .grouping .component import BaseGroupingComponent
7
+ from sentry .grouping .enhancer .matchers import MatchFrame
6
8
from sentry .utils .safe import get_path , set_path
7
9
8
10
from .exceptions import InvalidEnhancerConfig
9
11
12
+ if TYPE_CHECKING :
13
+ from sentry .grouping .enhancer .rules import EnhancementRule
14
+
10
15
ACTIONS = ["group" , "app" ]
11
16
ACTION_BITSIZE = 8
12
17
# Ensure that the number of possible actions is smaller than the number of numbers which can be
@@ -30,14 +35,18 @@ class EnhancementAction:
30
35
def apply_modifications_to_frame (
31
36
self ,
32
37
frames : Sequence [dict [str , Any ]],
33
- match_frames : Sequence [ dict [ str , Any ] ],
38
+ match_frames : list [ MatchFrame ],
34
39
idx : int ,
35
- rule : Any = None ,
40
+ rule : Any | None = None ,
36
41
) -> None :
37
42
pass
38
43
39
44
def update_frame_components_contributions (
40
- self , components , frames : Sequence [dict [str , Any ]], idx , rule = None
45
+ self ,
46
+ components : list [BaseGroupingComponent ],
47
+ frames : list [dict [str , Any ]],
48
+ idx : int ,
49
+ rule : Any | None = None ,
41
50
) -> None :
42
51
pass
43
52
@@ -55,7 +64,7 @@ def is_updater(self) -> bool:
55
64
return self ._is_updater
56
65
57
66
@classmethod
58
- def _from_config_structure (cls , val , version : int ):
67
+ def _from_config_structure (cls , val : list [ str ] | int , version : int ) -> EnhancementAction :
59
68
if isinstance (val , list ): # This is a `VarAction`
60
69
variable , value = val
61
70
return VarAction (variable , value )
@@ -88,7 +97,7 @@ def __str__(self) -> str:
88
97
self .key ,
89
98
)
90
99
91
- def _to_config_structure (self , version : int ):
100
+ def _to_config_structure (self , version : int ) -> int :
92
101
"""
93
102
Convert the action into an integer by
94
103
- converting the combination of its boolean value (if it's a `+app/+group` rule or a
@@ -100,7 +109,7 @@ def _to_config_structure(self, version: int):
100
109
"""
101
110
return ACTIONS .index (self .key ) | (ACTION_FLAGS [self .flag , self .range ] << ACTION_BITSIZE )
102
111
103
- def _slice_to_range (self , seq , idx ) :
112
+ def _slice_to_range (self , seq : list [ Any ] , idx : int ) -> list [ Any ] :
104
113
if self .range is None :
105
114
return [seq [idx ]]
106
115
elif self .range == "down" :
@@ -122,17 +131,21 @@ def _in_app_changed(self, frame: dict[str, Any]) -> bool:
122
131
def apply_modifications_to_frame (
123
132
self ,
124
133
frames : Sequence [dict [str , Any ]],
125
- match_frames : Sequence [ dict [ str , Any ] ],
134
+ match_frames : list [ MatchFrame ],
126
135
idx : int ,
127
- rule : Any = None ,
136
+ rule : Any | None = None ,
128
137
) -> None :
129
138
# Change a frame or many to be in_app
130
139
if self .key == "app" :
131
140
for match_frame in self ._slice_to_range (match_frames , idx ):
132
141
match_frame ["in_app" ] = self .flag
133
142
134
143
def update_frame_components_contributions (
135
- self , components , frames : Sequence [dict [str , Any ]], idx , rule = None
144
+ self ,
145
+ components : list [BaseGroupingComponent ],
146
+ frames : list [dict [str , Any ]],
147
+ idx : int ,
148
+ rule : EnhancementRule | None = None ,
136
149
) -> None :
137
150
rule_hint = "stack trace rule"
138
151
if rule :
@@ -184,19 +197,20 @@ def __init__(self, var: str, value: str) -> None:
184
197
def __str__ (self ) -> str :
185
198
return f"{ self .var } ={ self .value } "
186
199
187
- def _to_config_structure (self , version ):
200
+ def _to_config_structure (self , version : int ) -> list [str | int ]:
201
+ # TODO: Can we switch this to a tuple so we can type it more exactly?
188
202
return [self .var , self .value ]
189
203
190
- def modify_stacktrace_state (self , state , rule ):
204
+ def modify_stacktrace_state (self , state , rule ) -> None :
191
205
if self .var not in VarAction ._FRAME_VARIABLES :
192
206
state .set (self .var , self .value , rule )
193
207
194
208
def apply_modifications_to_frame (
195
209
self ,
196
210
frames : Sequence [dict [str , Any ]],
197
- match_frames : Sequence [ dict [ str , Any ] ],
211
+ match_frames : list [ MatchFrame ],
198
212
idx : int ,
199
- rule : Any = None ,
213
+ rule : Any | None = None ,
200
214
) -> None :
201
215
if self .var == "category" :
202
216
frame = frames [idx ]
0 commit comments