Closed valerian-chen closed 2 years ago
Two solutions for you:
1) the simple version:
if mode_flag not in [-1, 1]:
raise ValueError(
f"Bad value for `mode_flag`! Expected either 1 or -1, got '{mode_flag}'"
)
2) the fancy version:
from enum import IntEnum
class Mode(IntEnum):
O = 1
X = -1
mode_flag = Mode(mode_flag)
The second one will error if mode_flag
is not a member of Mode
, and allows users to specify the name of the mode directly: mode_flag = Mode.O
, or with either exactly 1 or -1.
Check that mode_flag is either 1 or -1 and nothing else