cloud-custodian / cel-python

Pure Python implementation of the Common Expression Language
Apache License 2.0
116 stars 22 forks source link

Evaluate a condition branch only if needed #51

Closed sewi-cpan closed 4 months ago

sewi-cpan commented 9 months ago

The CEL language definition suggests:

To get traditional left-to-right short-circuiting evaluation of logical operators, as in C or other languages (also called "McCarthy Evaluation"), the expression e1 && e2 can be rewritten e1 ? e2 : false. Similarly, e1 || e2 can be rewritten e1 ? true : e2.

cel-python used to evaluate the full tree before deciding if a branch will be used or not. This PR only evaluates a branch if selected by the condition.

Fixes https://github.com/cloud-custodian/cel-python/issues/50

linux-foundation-easycla[bot] commented 9 months ago

CLA Signed

The committers listed above are authorized under a signed CLA.

kapilt commented 9 months ago

thanks for the pr, lgtm although a test would be appreciated, would also appreciate a look by @slott56

slott56 commented 4 months ago

See https://github.com/cloud-custodian/cel-python/pull/63 which fixes this problem.