INNER CODE UNIT · Python
to_digit
O-X-L/ansible-opnsense · plugins/module_utils/helper/main.py:47
def to_digit(data: bool) -> int:
"""Converts a boolean to an integer (1 or 0)."""
return 1 if data else 0
def format_int(data: (int, str)) -> (int, str, None):
"""Safely converts numeric strings to integers while preserving None or non-numeric strings."""
if isinstance(data, int):
return data
if data is None:
return None
if data.isnumeric():
return int(data)
return data