icinga2-checks/checker/types.py

15 lines
288 B
Python
Raw Normal View History

2024-01-14 12:15:17 -07:00
from typing import Union
def try_float(value: str) -> Union[int, float, str]:
2023-12-19 22:43:21 -07:00
try:
return float(value)
except:
pass
try:
return int(value)
except:
pass
raise ValueError(f"Could not convert {value} to float or int")
# return value