cloud-custodian / cloud-custodian/cel-python

Implement string.contains() per CEL spec section 6.2.5

Ouverte Adaptée aux débutants
#180 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
enhancement
Langage dominant
Python
Étoiles
174
Forks
40
Métriques de merge des PR
Aucune PR mergée en 30 j

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

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

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Commencez dans src/celpy/celtypes.py avec StringType, puis examinez la table de dispatch des fonctions mentionnée dans l’issue. Exécutez l’expression celpy fournie pour reproduire la surcharge manquante. Le travail est terminé lorsque .contains() renvoie true pour une sous-chaîne présente et false dans le cas contraire, conformément à la spécification CEL.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
backend
Type d'issue
Fonctionnalité
Difficulté
2/5
Temps estimé
1-3 heures
Activité
Calme
Clarté
Clairement spécifiée
Accessibilité débutants
78/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.