fix: await async predicates in condition expressions#557
Merged
Conversation
The boolean expression combinators (custom_not, custom_and, custom_or, build_custom_operator) called predicates synchronously. When predicates were async, they returned unawaited coroutine objects which are always truthy, causing `not` to always return False, `and` to skip evaluation, and `or` to short-circuit incorrectly. Each combinator now checks `isawaitable()` on predicate results and returns a coroutine when needed, which CallbackWrapper.__call__ already knows how to await. Closes #535
The pre-commit hook was using ruff v0.8.1 while the lockfile had v0.15.0, causing import sorting differences between local and CI.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #557 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 25 25
Lines 1656 1713 +57
Branches 204 219 +15
=========================================
+ Hits 1656 1713 +57
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Add docstrings to empty async on_enter_state methods (S1186) - Use await asyncio.sleep(0) in async test hooks to satisfy S7503
|
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
custom_not,custom_and,custom_or,build_custom_operator) inspec_parser.pyto properly handle async predicatesisawaitable()on predicate results and returns a coroutine when needed, whichCallbackWrapper.__call__already knows how to awaitnot,and,or) with async predicatesRoot cause
The combinators called predicates synchronously (e.g.,
not predicate(*args, **kwargs)). When predicates were async, they returned unawaited coroutine objects. Since coroutines are always truthy:not <coroutine>always returnedFalse<coroutine> and xalways evaluatedx(skipping the actual check)<coroutine> or xalways short-circuited (returning the coroutine without checking)Closes #535