Structural Equality¶
All expression types support structural equality via Python's == operator and are hashable, allowing use in sets or as dict keys.
from therismos import F, AllExpr
age = F("age", int)
# Structural equality — same tree, same result
assert (age > 18) == (age > 18)
# Order-insensitive for commutative expressions (AND / OR / In)
e1 = AllExpr(age > 18, age < 65)
e2 = AllExpr(age < 65, age > 18)
assert e1 == e2 # order does not matter for AND
# Expressions are hashable
expr_set = {age > 18, age < 65, age > 18}
assert len(expr_set) == 2
Field Equality¶
Field.__eq__ is overloaded: it returns an Eq expression when compared to a plain value (DSL usage), but a bool when compared to another Field or expression object.