forked from scVENUS/PeekabooAV
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expressions: Short circuit logic operators
Our logic operators 'and' and 'or' would not short-circuit if the result was already conclusive. This would lead to unnecessary evaluation and broke user assumption that they could be used to run additional tests only if required. We fix that by introducing explicit short-circuiting and adding tests to document the problem and catch regressions. We also fix over-eager short-circuiting for compound 'or' operations by excluding both 'or' and 'and' from post-evaluation short-circuiting and deferring their short-circuiting to the next iteration based on the then-first operand. Finally, we explicitly document the distinction between operand passing within compound operations (such as 1 < 2 < 2) and their evaluation into boolean results. We opt (as we did implictly before) to always return booleans even for 'and' and 'or' which in python return the determing operand (1 or 2 -> 1 instead of True). In order to determine what operation we're looking at, we switch 'and' and 'or' from lambda functions to static methods. This now also allows tests to avoid error conditions like: foo is not None and "bar" in foo (NoneType not iterable in this case). Partially addresses scVENUS#176.
- Loading branch information
1 parent
e95fc8e
commit a44f8f7
Showing
2 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters