def try_enum(cls, val):
 try:
  return cls(val)
 except ValueError:
  return val

def try_enum ( cls , val ) : try : return cls ( val ) except ValueError : return val
a function that tries to turn the value into enum cls .