Skip to content
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

Feature request: Include a plain language description of why the rule failed #75

Open
logicbomb opened this issue Sep 8, 2023 · 2 comments
Labels
feature request Requests for new functionality

Comments

@logicbomb
Copy link

Expand the return type for matches to be a tuple [bool, str | None] where the 2nd element contains an explaination of the failure when bool = False

It would also be nice to give the rule an optional name
e.g.

matched, reason = Rule("flux-capacitor", "foo < 3 and bar == 1" ).matches({"foo": 5, "bar": 1})
# matched: False
# reason: "The flux-capacitor failed because the value of 'foo' is 5, it must be less than 3"

I might be able to take a stab at it, if you think it's a useful feature. I'd want to hammer out how to format multiple failures in a single rule.

@logicbomb
Copy link
Author

It may be more flexible to forgo naming the rule and extend the return type to be (bool, list[str] | None), basically return a readable string for each failure,

matched, reasons = Rule("foo < 3 and bar == 2" ).matches({"foo": 5, "bar": 1})
# matched: False
# reasons: ["The value of 'foo' is 5, it must be less than 3", "The value of 'bar' is 1, it must be 2"]

@zeroSteiner
Copy link
Owner

Yeah that could be interesting. If you do implement it, please add a new function instead of changing the return type of matches to ensure it's backwards compatible. Maybe something like matches_with_reasons, IDK.

@zeroSteiner zeroSteiner added the feature request Requests for new functionality label Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Requests for new functionality
Projects
None yet
Development

No branches or pull requests

2 participants