Skip to content

Commit

Permalink
clean up some types to avoid type narrowing
Browse files Browse the repository at this point in the history
  • Loading branch information
k-fish committed Oct 16, 2023
1 parent 124dd3b commit a91f25a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/sentry/snuba/metrics/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
{
Expand Down Expand Up @@ -674,19 +674,20 @@ 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):
op, metric_type, arguments = self._process_field()

self.op = op
self._metric_type = metric_type
self._arguments = arguments
self._arguments = arguments or []

@property
def field_to_extract(self):
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a91f25a

Please sign in to comment.