Replace eval() in the calculator tool with a safe AST-walking evaluator
that only allows arithmetic operations, math module functions, and a
whitelist of builtins (abs, round, min, max).
The new _safe_eval() function:
- Parses the expression into an AST tree
- Walks each node, only allowing:
- Numeric literals (int, float, complex)
- Binary ops (+, -, *, /, //, %, **)
- Unary ops (+, -)
- math.* attribute access
- Whitelisted function calls
- Rejects: imports, attribute chains, subscripts, comparisons,
lambdas, comprehensions, string operations, keyword args
No new dependencies — uses stdlib ast + operator modules.
Test coverage expanded from 18 to 33 tests, including security tests
for exec(), arbitrary attributes, lambdas, list comprehensions,
boolean ops, keyword args, and subscripts.