aiidateam / plumpy

A python workflows library that supports writing Processes with a well defined set of inputs and outputs that can be strung together.
https://plumpy.readthedocs.io
Other
8 stars 17 forks source link

Workchains: Raise if `if_/while_` predicate does not return boolean #259

Closed sphuber closed 1 year ago

sphuber commented 1 year ago

Fixes #258

The if_ and while_ conditionals are constructed with a predicate. The interface expects the predicate to be a callable that returns a boolean, which if true, the body of the conditional is entered.

The problem is that the type of the value returned by the predicate was not explicitly checked, and any value that would evaluate as truthy would be accepted. This could potentially lead to unexpected behavior, such as an infinite loop for the while_ construct.

Here the _Conditional.is_true method is updated to explicitly check the type of the value returned by the predicate. If anything but a boolean is returned, a TypeError is raised.

codecov[bot] commented 1 year ago

Codecov Report

Patch and project coverage have no change.

Comparison is base (e5a0ce1) 90.74% compared to head (e5a0ce1) 90.74%.

:exclamation: Current head e5a0ce1 differs from pull request most recent head bda08b3. Consider uploading reports for the commit bda08b3 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## support/0.21.x #259 +/- ## =============================================== Coverage 90.74% 90.74% =============================================== Files 21 21 Lines 2967 2967 =============================================== Hits 2692 2692 Misses 275 275 ``` Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.