8000 Short-circuit boolean evaluation, and return the determining value. · alex-python/pyScss@0f5a0bf · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f5a0bf

Browse files
committed
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.
1 parent 742351d commit 0f5a0bf

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

scss/expression.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,11 @@ def __init__(self, *operands):
232232
self.operands = operands
233233

234234
def evaluate(self, calculator, divide=False):
235-
operands = [operand.evaluate(calculator, divide=True) for operand in self.operands]
236-
return Boolean(any(operands))
235+
for operand in self.operands:
236+
value = operand.evaluate(calculator, divide=True)
237+
if value:
238+
return value
239+
return value
237240

238241

239242
class AllOp(Expression):
@@ -244,8 +247,11 @@ def __init__(self, *operands):
244247
self.operands = operands
245248

246249
def evaluate(self, calculator, divide=False):
247-
operands = [operand.evaluate(calculator, divide=True) for operand in self.operands]
248-
return Boolean(all(operands))
250+
for operand in self.operands:
251+
value = operand.evaluate(calculator, divide=True)
252+
if not value:
253+
return value
254+
return value
249255

250256

251257
class NotOp(Expression):

0 commit comments

Comments
 (0)
0