Add substring() function to stdlib and improve logging #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add
substring()function to stdlib and improve loggingThis PR introduces a new
cel.stdlibmodule with Python implementations of CEL functions missing from upstream cel-rust, and improves logging levels for execution errors.🎯 Changes
1. New Standard Library Module
python/cel/stdlib.py- Python implementations of missing CEL standard library functionssubstring(str, start, end?)functionadd_stdlib_to_context()convenience functionSTDLIB_FUNCTIONSdict for future additions2. CLI Auto-loads stdlib
python/cel/cli.pysubstringto syntax highlightingsubstringto autocomplete3. Logging Improvements
src/lib.rs(version 0.5.3)warn!todebug!level4. Documentation Updates
Updated
docs/reference/cel-compliance.mdUpdated
docs/reference/cli-reference.mdUpdated error handling docs - Fixed error message assertions to use "Failed to parse expression"
🧪 Test Coverage
Added
tests/test_stdlib.py(14 tests)Updated
tests/test_cli.py(2 new tests)All tests passing: 342 passed, 1 skipped, 7 xfailed
📝 Usage Example
Programmatic API:
CLI (auto-included):
🔍 Design Decisions
Function syntax, not method syntax:
substring("text", 0, 5)instead of"text".substring(0, 5)CLI auto-loads stdlib: Better UX - functions work without setup
Upstream detection: Tests will fail when cel-rust adds native support, alerting us to switch to native implementation
Extensible pattern: Easy to add more stdlib functions in the future