Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clarified the typing in the class PrometheusQueryResult #26

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading