cloud-custodian / cloud-custodian/cel-python

Implement string.contains() per CEL spec section 6.2.5

Đang mở
#180 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
Python
Star
174
Fork
40
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

## 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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.