Skip to content

Commit

Permalink
Merge pull request #26 from robusta-dev/Added-better-typing-annotation
Browse files Browse the repository at this point in the history
clarified the typing in the class PrometheusQueryResult
  • Loading branch information
arikalon1 authored Sep 25, 2024
2 parents 6a618a2 + bb8e7a1 commit bcf674d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions prometrix/models/prometheus_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ def __init__(self, data: Dict):
self.string_result = None

if result_type == "string" or result_type == "error":
self.string_result = str(result)
self.string_result: str = str(result)
elif result_type == "scalar" and isinstance(result, list):
self.scalar_result = PrometheusScalarValue(result).to_dict()
self.scalar_result: Dict[str, any] = PrometheusScalarValue(result).to_dict()
elif result_type == "vector" and isinstance(result, list):
self.vector_result = self._format_vector(result)
self.vector_result: List[Dict[str, any]] = self._format_vector(result)
elif result_type == "matrix" and isinstance(result, list):
self.series_list_result = self._format_series(result)
self.series_list_result: List[Dict[str, any]] = self._format_series(result)
else:
raise ValueError("result or returnType is invalid")

def _format_vector(self, vector: List):
def _format_vector(self, vector: List) -> List[Dict[str, any]]:
""" Convert vector result into a list of dictionaries for JSON """
return [
{
Expand All @@ -79,7 +79,7 @@ def _format_vector(self, vector: List):
for vector_item in vector
]

def _format_series(self, series: List):
def _format_series(self, series: List) -> List[Dict[str, any]]:
""" Convert matrix (series) result into a list of PrometheusSeries dictionaries for JSON """
return [
PrometheusSeries(series_item["metric"], series_item["values"]).to_dict()
Expand Down

0 comments on commit bcf674d

Please sign in to comment.