Skip to content

Commit bcf674d

Browse files
authored
Merge pull request #26 from robusta-dev/Added-better-typing-annotation
clarified the typing in the class PrometheusQueryResult
2 parents 6a618a2 + bb8e7a1 commit bcf674d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

prometrix/models/prometheus_result.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ def __init__(self, data: Dict):
5959
self.string_result = None
6060

6161
if result_type == "string" or result_type == "error":
62-
self.string_result = str(result)
62+
self.string_result: str = str(result)
6363
elif result_type == "scalar" and isinstance(result, list):
64-
self.scalar_result = PrometheusScalarValue(result).to_dict()
64+
self.scalar_result: Dict[str, any] = PrometheusScalarValue(result).to_dict()
6565
elif result_type == "vector" and isinstance(result, list):
66-
self.vector_result = self._format_vector(result)
66+
self.vector_result: List[Dict[str, any]] = self._format_vector(result)
6767
elif result_type == "matrix" and isinstance(result, list):
68-
self.series_list_result = self._format_series(result)
68+
self.series_list_result: List[Dict[str, any]] = self._format_series(result)
6969
else:
7070
raise ValueError("result or returnType is invalid")
7171

72-
def _format_vector(self, vector: List):
72+
def _format_vector(self, vector: List) -> List[Dict[str, any]]:
7373
""" Convert vector result into a list of dictionaries for JSON """
7474
return [
7575
{
@@ -79,7 +79,7 @@ def _format_vector(self, vector: List):
7979
for vector_item in vector
8080
]
8181

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

0 commit comments

Comments
 (0)