-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for infix Boolean logical operators #2835
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2835 +/- ##
==========================================
- Coverage 87.19% 87.19% -0.01%
==========================================
Files 765 765
Lines 88471 88504 +33
==========================================
+ Hits 77146 77171 +25
- Misses 11325 11333 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
NFC: Fixing typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wheeee, thank you for this! It is indeed much prettier syntax.
We omit support for most infix operators, e.g. :code:`Y[1] >> Y[2]`, due to concerns about non-intuitive Python operator precedence. | ||
We omit support for some infix operators, e.g. :code:`Y[1] >> Y[2]`, due to concerns about non-intuitive Python operator precedence. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually... Do we need this line of documentation at all? Isn't it just telling mice about cookies we're never planning on baking anyway?
Fixes # .
Summary/Motivation:
The initial implementation of the logical expression system intentionally omitted most infix "Boolean" operators because the "attractive" operators in Python had precedence that differs from their use in logical expressions. In particular, using the shift operator (
>>
) for implication caused problems. However, using bitwise operators (&
,|
, and^
) for BooleanVar / logical expressions does not have that problem.This PR adds infix implementations for AND, OR, and XOR operations on BooleanValue objects (and thus all logical expressions)
This PR does NOT implement
__eq__
, or__ne__
(although a later PR probably should ... and will be needed for #2541)Changes proposed in this PR:
__and__
,__or__
, and__xor__
(along with their reversed and inplace versions) for BooleanValue objectsLegal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: