diff options
author | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2013-08-28 16:58:15 -0700 |
---|---|---|
committer | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2013-08-28 17:09:16 -0700 |
commit | 0f5a0bf64a2427ccde209129ece231be9fcfd548 (patch) | |
tree | 71bcab8680f714bcbccf96f7587b0e280cac3704 | |
parent | 742351d6744718a38e3af22529950c6e07ee738d (diff) | |
download | pyscss-0f5a0bf64a2427ccde209129ece231be9fcfd548.tar.gz |
Short-circuit boolean evaluation, and return the determining value.
This acts much more like Python; now we don't even evaluate the AST once
we know the result.
-rw-r--r-- | scss/expression.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/scss/expression.py b/scss/expression.py index 45c6bca..959ac34 100644 --- a/scss/expression.py +++ b/scss/expression.py @@ -232,8 +232,11 @@ class AnyOp(Expression): self.operands = operands def evaluate(self, calculator, divide=False): - operands = [operand.evaluate(calculator, divide=True) for operand in self.operands] - return Boolean(any(operands)) + for operand in self.operands: + value = operand.evaluate(calculator, divide=True) + if value: + return value + return value class AllOp(Expression): @@ -244,8 +247,11 @@ class AllOp(Expression): self.operands = operands def evaluate(self, calculator, divide=False): - operands = [operand.evaluate(calculator, divide=True) for operand in self.operands] - return Boolean(all(operands)) + for operand in self.operands: + value = operand.evaluate(calculator, divide=True) + if not value: + return value + return value class NotOp(Expression): |