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