more explicit typing when decoding

This commit is contained in:
Linus Vogel 2026-06-18 22:53:53 +02:00
parent 4c649f90bc
commit fe5ee5bd4d

View File

@ -13,12 +13,12 @@ def get_pillar_name_sequence(name: str) -> list[str]:
def decode_pillar_value(pillar: Pillar) -> str | int | float | bool | list | dict: def decode_pillar_value(pillar: Pillar) -> str | int | float | bool | list | dict:
match pillar.parameter_type: match pillar.parameter_type:
case 'string': return json.loads(pillar.value) case 'string': return str(json.loads(pillar.value))
case 'integer': return json.loads(pillar.value) case 'integer': return int(json.loads(pillar.value))
case 'float': return json.loads(pillar.value) case 'float': return float(json.loads(pillar.value))
case 'boolean': return json.loads(pillar.value) case 'boolean': return bool(json.loads(pillar.value))
case 'list': return json.loads(pillar.value) case 'list': return list(json.loads(pillar.value))
case 'dict': return json.loads(pillar.value) case 'dict': return dict(json.loads(pillar.value))
raise RuntimeError(f"Failed to decode pillar value: Invalid type '{pillar.parameter_type}'") raise RuntimeError(f"Failed to decode pillar value: Invalid type '{pillar.parameter_type}'")