1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
from typing import Any, Optional
def is_integer_between(
x: int, mn: Optional[int] = None, mx: Optional[int] = None, optional: bool = False
) -> bool:
if optional and x is None:
return True
try:
if mn is not None and mx is not None:
return int(x) >= mn and int(x) < mx
elif mn is not None:
return int(x) >= mn
elif mx is not None:
return int(x) < mx
else:
return True
except ValueError:
return False
def is_one_of(x: Any, choices: Any, optional: bool = False) -> bool:
if optional and x is None:
return True
return x in choices
|