Implement string.contains() per CEL spec section 6.2.5
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start in src/celpy/celtypes.py with StringType and then inspect the function dispatch table mentioned in the issue. Run the provided celpy expression to reproduce the missing overload. Done means .contains() returns true for a present substring and false otherwise, matching the CEL specification.
Written by the indexing model from the issue text.
Description
Summary
The CEL specification (section 6.2.5) defines string.contains(string) -> bool as a standard string function. Currently, calling .contains() on a StringType raises CELEvalError: no such overload in cel-python.
Steps to reproduce
import celpy
env = celpy.Environment()
ast = env.compile('"hello world".contains("world")')
prog = env.program(ast)
result = prog.evaluate({})
print(result) # Expected: true
Actual behaviour
celpy.celenv.CELEvalError: no such overload
Expected behaviour
contains() should return true when the substring is present and false otherwise, matching the Go and Java CEL implementations.
Proposed fix
Add a contains method to StringType in src/celpy/celtypes.py:
def contains(self, other: 'StringType') -> BoolType:
return BoolType(str(other) in str(self))
And register the overload in the function dispatch table so that "x".contains("y") is correctly dispatched.
Related
- Issue #128 (user question about
.contains()not working) - CEL spec reference: https://github.com/google/cel-spec/blob/master/doc/langdef.md#standard-definitions
- Dominant language
- Python
- Stars
- 174
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cloud-custodian/cel-python
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
cloud-custodian/cel-python#194 ·
-
documentation enhancement tracking
Difficulty 3/5 1-2 days Newbie friendliness 68/100
cloud-custodian/cel-python#182 ·
-
Refresh Features Opendependencies
cloud-custodian/cel-python#172 · 2 comments · 1 assignee ·
-
enhancement
cloud-custodian/cel-python#169 · 3 comments · 1 assignee ·
-
bug
cloud-custodian/cel-python#145 · 4 comments · 2 assignees ·
All issues in cloud-custodian/cel-python
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100