[F] Fix prep6

This commit is contained in:
Hykilpikonna
2022-02-12 10:08:44 -05:00
parent 91c0cbb42c
commit eaaf757612
+14 -2
View File
@@ -300,10 +300,22 @@ class Compare(Expr):
... ('<=', Num(4.5))])
>>> expr.evaluate()
False
>>> expr = Compare(Num(1), [
... ('<=', Num(4.5)),
... ('<=', Num(2)),
... ('<', Num(4.5))])
>>> expr.evaluate()
False
"""
left = self.left.evaluate()
return all((left < c[1].evaluate() if c[0] == '<' else left <= c[1].evaluate())
for c in self.comparisons)
for c in self.comparisons:
v = c[1].evaluate()
if c[0] == '<' and left >= v:
return False
if c[0] == '<=' and left > v:
return False
left = v
return True
def __str__(self) -> str:
"""Return a string representation of this comparison expression.