cloud-custodian / cloud-custodian/cel-python
Implement string.contains() per CEL spec section 6.2.5
- 主要语言
- Python
- 星标
- 174
- 派生
- 40
- PR 合并指标
- 30 天内没有已合并 PR
描述
## 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
```python
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`:
```python
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
贡献指南
这个仓库没有索引到贡献指南
调研方向
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.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 功能
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 78/100