@@ -118,7 +118,9 @@ def validate_type(self, value: str) -> Condition:
118118
119119 return type
120120
121- def validate_comparison (self , value : dict | float | int | str ) -> float | dict :
121+ def validate_comparison (
122+ self , value : dict [str , Any ] | float | int | str
123+ ) -> float | dict [str , Any ]:
122124 if isinstance (value , (float , int )):
123125 try :
124126 value = float (value )
@@ -147,7 +149,7 @@ def validate_condition_result(self, value: str) -> DetectorPriorityLevel:
147149class MetricIssueConditionGroupValidator (BaseDataConditionGroupValidator ):
148150 conditions = serializers .ListField (required = True )
149151
150- def validate_conditions (self , value ) :
152+ def validate_conditions (self , value : list [ dict [ str , Any ]]) -> list [ dict [ str , Any ]] :
151153 MetricIssueComparisonConditionValidator (data = value , many = True ).is_valid (
152154 raise_exception = True
153155 )
@@ -160,10 +162,12 @@ def validate_conditions(self, value):
160162 return value
161163
162164
163- def is_invalid_extrapolation_mode (new_extrapolation_mode ) -> bool :
164- if type (new_extrapolation_mode ) is int :
165+ def is_invalid_extrapolation_mode (
166+ new_extrapolation_mode : int | str | ExtrapolationMode | None ,
167+ ) -> bool :
168+ if isinstance (new_extrapolation_mode , int ):
165169 new_extrapolation_mode = ExtrapolationMode (new_extrapolation_mode ).name .lower ()
166- if type (new_extrapolation_mode ) is ExtrapolationMode :
170+ if isinstance (new_extrapolation_mode , ExtrapolationMode ) :
167171 new_extrapolation_mode = new_extrapolation_mode .name .lower ()
168172 if (
169173 new_extrapolation_mode is not None
@@ -179,12 +183,14 @@ def is_invalid_extrapolation_mode(new_extrapolation_mode) -> bool:
179183 return False
180184
181185
182- def format_extrapolation_mode (extrapolation_mode ) -> ExtrapolationMode | None :
186+ def format_extrapolation_mode (
187+ extrapolation_mode : int | str | ExtrapolationMode | None ,
188+ ) -> ExtrapolationMode | None :
183189 if extrapolation_mode is None :
184190 return None
185- if type (extrapolation_mode ) is int :
191+ if isinstance (extrapolation_mode , int ) :
186192 return ExtrapolationMode (extrapolation_mode )
187- if type (extrapolation_mode ) is ExtrapolationMode :
193+ if isinstance (extrapolation_mode , ExtrapolationMode ) :
188194 return extrapolation_mode
189195 return ExtrapolationMode .from_str (extrapolation_mode )
190196
@@ -195,7 +201,7 @@ class MetricIssueDetectorValidator(BaseDetectorTypeValidator):
195201 )
196202 condition_group = MetricIssueConditionGroupValidator (required = True )
197203
198- def validate_eap_rule (self , attrs ) :
204+ def validate_eap_rule (self , attrs : dict [ str , Any ]) -> None :
199205 """
200206 Validate EAP rule data.
201207 """
@@ -209,7 +215,7 @@ def validate_eap_rule(self, attrs):
209215 aggregate = data_source .get ("aggregate" )
210216 validate_trace_metrics_aggregate (aggregate )
211217
212- def validate (self , attrs ) :
218+ def validate (self , attrs : dict [ str , Any ]) -> dict [ str , Any ] :
213219 attrs = super ().validate (attrs )
214220
215221 if "condition_group" in attrs :
@@ -290,7 +296,7 @@ def is_editing_transaction_dataset(
290296
291297 def update_data_source (
292298 self , instance : Detector , data_source : SnubaQueryDataSourceType , seer_updated : bool = False
293- ):
299+ ) -> None :
294300 try :
295301 source_instance = DataSource .objects .get (detector = instance )
296302 except DataSource .DoesNotExist :
@@ -382,7 +388,7 @@ def update_anomaly_detection(self, instance: Detector, validated_data: dict[str,
382388
383389 return seer_updated
384390
385- def update (self , instance : Detector , validated_data : dict [str , Any ]):
391+ def update (self , instance : Detector , validated_data : dict [str , Any ]) -> Detector :
386392 # Handle anomaly detection changes first in case we need to exit before saving so that the instance values do not get updated
387393 seer_updated = self .update_anomaly_detection (instance , validated_data )
388394
@@ -413,7 +419,7 @@ def update(self, instance: Detector, validated_data: dict[str, Any]):
413419 schedule_update_project_config (instance )
414420 return instance
415421
416- def create (self , validated_data : dict [str , Any ]):
422+ def create (self , validated_data : dict [str , Any ]) -> Detector :
417423 if "data_sources" in validated_data :
418424 for validated_data_source in validated_data ["data_sources" ]:
419425 self ._validate_transaction_dataset_deprecation (validated_data_source .get ("dataset" ))
@@ -434,15 +440,15 @@ def create(self, validated_data: dict[str, Any]):
434440 schedule_update_project_config (detector )
435441 return detector
436442
437- def delete (self ):
443+ def delete (self ) -> None :
438444 # Let Seer know we're deleting a dynamic detector so the data can be deleted there too
439445 assert self .instance is not None
440446 detector : Detector = self .instance
441447 delete_data_in_seer_for_detector (detector )
442448
443449 super ().delete ()
444450
445- def _mark_query_as_user_updated (self , snuba_query : SnubaQuery ):
451+ def _mark_query_as_user_updated (self , snuba_query : SnubaQuery ) -> None :
446452 """
447453 Mark the snuba query as user-updated in the query_snapshot field.
448454 This is used to skip automatic migrations for queries that users have already modified.
0 commit comments