axiacore / py-expression-eval

MIT License
149 stars 54 forks source link

Support comparison chaining #60

Open k3an3 opened 3 years ago

k3an3 commented 3 years ago

In Python, the following syntax is valid:

>>> x = 7
>>> 5 < x < 10
True
>>> x = 1
>>> 5 < x < 10
False

However, this does not work in py-expression-eval:

>>> from py_expression_eval import Parser
>>> parser = Parser()
>>> parser.parse('5 < x < 10').evaluate({'x': 7})
True
>>> parser.parse('5 < x < 10').evaluate({'x': 1})
True

The last result is unexpected; the parser unconditionally returns True when chaining comparison.