Check custom functions return expected type
** Test to Update **
Add tests to check if a custom functions the user passes in return a bool (e.g., event_strategy). If custom function does not return a bool, show a warning noting potential unanticipated behavior.
- Add a Helper Function to Validate Return Type
progpy/utils/validators.py
from typing import Callable
def validate_bool_return(func: Callable) -> Callable: """ Decorator to ensure the function returns a boolean value. """ def wrapper(*args, **kwargs): result = func(*args, **kwargs) if not isinstance(result, bool): raise ValueError(f"Function {func.name} must return a boolean value.") return result return wrapper
- Apply the Decorator to Custom Functions
Example usage in a model or algorithm
from progpy.utils.validators import validate_bool_return
class CustomModel: @validate_bool_return def event_strategy(self, state): # Custom logic return True # Ensure this returns a boolean
- Explanation
What this does: Ensures that custom functions like event_strategy return a boolean value, preventing potential runtime errors.
Why this fixes it: By enforcing a boolean return type, we maintain consistency and prevent unexpected behavior in the system.
Next steps: Apply this decorator to all relevant custom functions within the codebase.