Skip to content

Improve the restricted expression evaluator (eval_utils.py) #120

@amc-corey-cox

Description

@amc-corey-cox

Context

linkml-map's eval_utils.py is a fork of linkml_runtime.utils.eval_utils with some improvements (fixed None handling bug, added eval_expr_with_mapping()), but the expression evaluator is still missing basic operators that users would reasonably expect.

The long-term goal (per #98) is to unify the expression language across the LinkML ecosystem. Before upstreaming anything, we should make the evaluator here actually good and well-tested.

Missing operators and features

The safe evaluator currently lacks:

  • != (not equal) — despite == being supported
  • and, or (logical operators via ast.BoolOp)
  • not (logical negation via ast.UnaryOp / ast.Not)
  • in, not in (membership testing)
  • % (modulo)
  • // (floor division)

Other improvements

  • Remove dead Python 3.7 compat branches (ast.Num, ast.Str, ast.NameConstant, ast.Index) — the project requires 3.9+
  • Add comprehensive tests for all operators and edge cases
  • Document what the expression language supports

Out of scope (for now)

  • List comprehensions, multi-statement blocks, assignment — these require unrestricted_eval=True and the asteval fallback. That's a separate concern.
  • Upstreaming to linkml/linkml — do this once the evaluator is solid.

Related

Sub-issue of #98

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions