From a91f25a7b0f9bd95d9e9558b45c79d95d84ef2f4 Mon Sep 17 00:00:00 2001 From: Kev Date: Mon, 16 Oct 2023 19:22:01 -0400 Subject: [PATCH] clean up some types to avoid type narrowing --- src/sentry/snuba/metrics/extraction.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/sentry/snuba/metrics/extraction.py b/src/sentry/snuba/metrics/extraction.py index 7f0cd93f203d08..e7164d18ba086f 100644 --- a/src/sentry/snuba/metrics/extraction.py +++ b/src/sentry/snuba/metrics/extraction.py @@ -579,10 +579,10 @@ def _deep_sorted(value: Union[Any, Dict[Any, Any]]) -> Union[Any, Dict[Any, Any] return value -TagsSpecsGenerator = Callable[[Project, Optional[str]], List[TagSpec]] +TagsSpecsGenerator = Callable[[Project, Optional[Sequence[str]]], List[TagSpec]] -def failure_tag_spec(_1: Project, _2: Optional[str]) -> List[TagSpec]: +def failure_tag_spec(_1: Project, _2: Optional[Sequence[str]]) -> List[TagSpec]: """This specification tags transactions with a boolean saying if it failed.""" return [ { @@ -674,11 +674,12 @@ class OnDemandMetricSpec: # Private fields. _metric_type: str - _arguments: Optional[Sequence[str]] + _arguments: Sequence[str] def __init__(self, field: str, query: str): self.field = field self.query = query + self._arguments = [] self._eager_process() def _eager_process(self): @@ -686,7 +687,7 @@ def _eager_process(self): self.op = op self._metric_type = metric_type - self._arguments = arguments + self._arguments = arguments or [] @property def field_to_extract(self): @@ -773,7 +774,7 @@ def to_metric_spec(self, project: Project) -> MetricSpec: return metric_spec - def _process_field(self) -> Tuple[MetricOperationType, str, Optional[list[str]]]: + def _process_field(self) -> Tuple[MetricOperationType, str, Optional[Sequence[str]]]: parsed_field = self._parse_field(self.field) if parsed_field is None: raise Exception(f"Unable to parse the field {self.field}") @@ -829,7 +830,7 @@ def _aggregate_conditions(parsed_field) -> Optional[RuleCondition]: @staticmethod def _parse_arguments( op: MetricOperationType, metric_type: str, parsed_field: FieldParsingResult - ) -> Optional[list[str]]: + ) -> Optional[Sequence[str]]: requires_arguments = metric_type in ["s", "d"] or op in ["on_demand_apdex"] if not requires_arguments: return None