fix: coerce condition predicate result to bool before comparing to target#741
Open
gaoflow wants to merge 1 commit into
Open
fix: coerce condition predicate result to bool before comparing to target#741gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
…rget
Condition.check() compared the predicate return value directly with
self.target using ==, which fails for non-bool truthy/falsy values:
'yes' == True → False (should pass a truthy condition)
[1,2] == True → False (should pass a truthy condition)
'' == False → False (should pass an unless condition)
None == False → False (should pass an unless condition)
Python's == operator only considers 0/False and 1/True as equal;
any other truthy or falsy value compares unequal to True or False.
Fix by wrapping the predicate result in bool() before the comparison,
mirroring how Python's if-statement handles truthiness. The same
one-liner bug existed in AsyncCondition.check().
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Condition.check()used strict equality (==) to compare the predicatereturn value against
self.target(TrueorFalse). This silentlyfails for any non-bool truthy or falsy value because Python's
==operator only considers
0/Falseand1/Trueas equal — all othertruthy/falsy values compare unequal:
Reproducer:
Fix
Wrap the predicate result in
bool()before the== self.targetcomparison, matching how Python's
if-statement handles truthiness.The same bug was present in
AsyncCondition.check().All 71 existing tests pass.