def evaluate(self, query: MutableMapping[str, Any], context: PipelineContext = None) -> bool:
# We can't short circuit this because we want to raise any WrongValueTypeError or BoundKeyExistenceError that could occur.
# We count failures because the only other node than can return False is a KeyNode that isn't required. An OrNode is only
# allowed to return False when all its children are False KeyNodes. The AndNodes handle raising an error if a can_have
# expression with ands and ors fails.
errors = []
failure_count = 0
result = False
for child in self.children:
try:
is_true = child.evaluate(query, context)
if not is_true:
failure_count += 1
result = is_true or result
except (MissingKeyError, BoundKeyExistenceError) as error:
errors.append(error)
failure_count += 1
if failure_count == len(self.children) and len(errors) > 0:
raise errors[0]
return result
评论列表
文章目录