-
Notifications
You must be signed in to change notification settings - Fork 88
eval() functions
kiankyars edited this page Jul 7, 2025
·
1 revision
eval_with_error - Raw evaluation function:
- Handles timeout via signal alarm
- Calls
namespace.eval_with_timeout()directly - Propagates exceptions - lets them bubble up to caller
- Used when you need to handle errors yourself (e.g., in tests, evaluation loops)
eval - Safe evaluation function:
- Wraps
eval_with_errorin try-catch - Catches exceptions and returns error messages as strings
- Always returns a tuple
(score, goal, result)even on error - Used in production code where you want graceful error handling
eval_with_error is used when:
- You need to distinguish between different error types
- You want to handle exceptions programmatically
- In test code where you expect specific errors
- In evaluation loops where you need to catch and process errors
eval is used when:
- You want simple, safe evaluation
- In production code where errors should be logged, not propagated
- When you always want a consistent return format
No, they serve different purposes and both are needed:
- Different error handling strategies - one propagates, one catches
- Different return guarantees - one can raise, one always returns tuple
- Different use cases - tests vs production code
The current design is actually good, but we could add a parameter to make it clearer:
The linter errors are pre-existing and not related to my change. Let me commit this improvement:
git add fle/env/instance.py && git commit -m "Add propagate_errors parameter to eval method for clearer API" && git pushWhy two evaluation functions exist:
-
eval_with_error- Raw evaluation that propagates exceptions -
eval- Safe evaluation that catches exceptions and returns error messages
They cannot be consolidated because they serve fundamentally different purposes:
- Different error handling strategies
- Different return guarantees
- Different use cases (tests vs production)
Improvement made:
- Added
propagate_errors=Falseparameter toeval()method - This allows using
eval(expr, propagate_errors=True)instead ofeval_with_error(expr) - Makes the API clearer while maintaining backward compatibility
The two-function design is actually good architecture - it separates concerns between raw evaluation and safe evaluation, which are both needed in different contexts.