Open logicbomb opened 1 year ago
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"]
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.
Expand the return type for matches to be a tuple
[bool, str | None]
where the 2nd element contains an explaination of the failure whenbool = False
It would also be nice to give the rule an optional name e.g.
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.