def evaluate(self, query: MutableMapping[str, Any], context: PipelineContext = None) -> True:
# This is a little weird. We have to handle the case of can_have("x").and_("y") here.
# Since the only type of Node that can return False rather than just raising a
# QueryValidationError is a KeyNode that isn't required, or an OrNode whose children
# are all KeyNodes that aren't required, we can't short circuit on a False value. If
# we have can_have("x").and_("y"), and only some are True, we want raise a
# QueryValidationError. If all are True or all are False, everything's fine.
all_true = True
all_possible_false = True
for child in self.children:
is_true = child.evaluate(query, context)
all_true = all_true and is_true
if child.falsifiable:
all_possible_false = all_possible_false and not is_true
if all_possible_false or all_true:
return True
raise BoundKeyExistenceError("Query must have all or none of the elements joined with \"and\" in a \"can_have\" statement!")
评论列表
文章目录