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
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
src/celpy/celtypes.py の StringType から始め、その後、issue で言及されている関数ディスパッチテーブルを確認します。提供された celpy 式を実行して、不足しているオーバーロードを再現します。.contains() が存在する部分文字列に対して true を返し、それ以外の場合に false を返すようになれば完了です。これは CEL 仕様に準拠します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- 機能追加
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 静か
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 78/100