I have a class with some method like this
class Validator:
def _is_valid_code(self):
return bool(#some logic here)
def _is_valid_role(self):
return bool(#some logic here)
def _is_valid_age(self):
return bool(#some logic here)
.
.
.
if all of them are True I want to continue, else return a string
if not _is_valid_code():
#short circuit and return a string
return "not valid code"
if not _is_valid_role():
#short circuit and return a string
return "not valid role"
if not _is_valid_age():
#short circuit and return a string with description
return "not valid age"
#if we got here the request is valid so return a valid response
return valid_scenario
Now I do not have any problem with this because there are just three conditions, but for example, if I have more, let say like 10 conditions, I would end up with a lot of if scenarios, so I was thinking if something like this is possible, where I just add the condition logic and the condition to the list and that's it, the problem is to get the string value if the condition is false
conditions = [_is_valid_code(), _is_valid_role(), _is_valid_age()]
if all_conditions_true(conditions):
return valid_scenario
else:
return last_message_before_shortcut
Also want to know if this is valid and if this could be considered pythonic and recommended