Closed matias-eb closed 4 years ago
That sounds like a documentation error then because the error is what I would expect. Python-style tuples using parenthesis are not valid. Array literals need to be defined with brackets. So what you're trying to do would be like:
In [5]: rule_engine.Rule('number in [1, 2]').evaluate(dict(number=1))
Out[5]: True
In [6]: rule_engine.Rule('number in [1, 2]').evaluate(dict(number=3))
Out[6]: False
I couldn't find where in the documentation it specifics that is valid syntax. There's actually no mention of defining array literals which is something I should fix.
You can use both tuples and lists as the value for a valid array. That would look something like:
In [4]: rule_engine.Rule('1 in numbers').evaluate(dict(numbers=(1, 2, 3)))
Out[4]: True
In [5]: rule_engine.Rule('1 in numbers').evaluate(dict(numbers=[4, 5, 6]))
Out[5]: False
Maybe that's what you were thinking of.
Yes, I would do it in that way. Thank you
Yes we should document the in operator use in the documentation like such
rule_engine.Rule('number in [1, 2]').evaluate(dict(number=1))
I am trying to do something like
rule_engine.Rule('number in (1, 2)')
and I am getting the following error:RuleSyntaxError: ('syntax error', LexToken(COMMA,',',1,14))
and according to documentation tuples can be used as array structures.