-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcel.pyi
More file actions
104 lines (83 loc) · 3.15 KB
/
Copy pathcel.pyi
File metadata and controls
104 lines (83 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
Type stubs for the CEL Rust extension module.
"""
from typing import Any, Callable, Dict, Literal, Optional, Union, overload
class Context:
"""CEL evaluation context for variables and functions."""
@overload
def __init__(self) -> None: ...
@overload
def __init__(self, variables: Dict[str, Any]) -> None: ...
@overload
def __init__(
self,
variables: Optional[Dict[str, Any]] = None,
*,
functions: Optional[Dict[str, Callable[..., Any]]] = None,
) -> None: ...
def add_variable(self, name: str, value: Any) -> None:
"""Add a variable to the context."""
...
def add_function(self, name: str, func: Callable[..., Any]) -> None:
"""Add a function to the context."""
...
def set_variable_resolver(self, resolver: Callable[[str], Any]) -> None:
"""Register a callback for lazy variable resolution.
The callback receives a variable name and returns the value, or None
to fall through to variables added via add_variable().
"""
...
def update(self, variables: Dict[str, Any]) -> None:
"""Update context with variables from a dictionary."""
...
class Program:
"""Compiled CEL program that can be executed multiple times."""
@property
def source(self) -> str:
"""The original CEL source this program was compiled from."""
...
def execute(self, context: Optional[Union[Dict[str, Any], Context]] = None) -> Any:
"""Execute the compiled program with an optional context."""
...
def variables(self) -> list[str]:
"""Return the sorted variable names this expression references.
Performs static analysis without evaluating the expression. Names bound
by comprehension macros (e.g. the ``x`` in ``[1, 2].map(x, x * 2)``) are
included, since they appear as identifiers.
"""
...
def functions(self) -> list[str]:
"""Return the sorted function/operator names this expression references.
Includes named functions (``size``) and CEL operator overload
identifiers for operators used in the expression (e.g. ``_+_``).
"""
...
def references(self) -> Dict[str, list[str]]:
"""Return ``{"variables": [...], "functions": [...]}`` for this expression."""
...
def compile(expression: str) -> Program:
"""Compile a CEL expression into a reusable Program object."""
...
class OptionalValue:
"""Wrapper for CEL optional values."""
@classmethod
def of(cls, value: Any) -> OptionalValue: ...
@classmethod
def none(cls) -> OptionalValue: ...
def has_value(self) -> bool: ...
def value(self) -> Any: ...
def or_value(self, default: Any) -> Any: ...
def or_optional(self, other: OptionalValue) -> OptionalValue: ...
def evaluate(
expression: str,
context: Optional[Union[Dict[str, Any], Context]] = None,
) -> Any:
"""
Evaluate a CEL expression.
Args:
expression: The CEL expression to evaluate
context: Optional context with variables and functions
Returns:
The result of evaluating the expression
"""
...