Skip to content

Commit 06752e1

Browse files
dmitriplotnikovcopybara-github
authored andcommitted
Add support for type signatures in CEL environment YAML configuration.
The `env_yaml` parser now accepts type signatures for variable types and function overload signatures. The `type` field can be used instead of `type_name` for variables, allowing a more compact representation of types, including type parameters and parameterized types. The `signature` field can be used for function overloads, providing a single string to define the overload's target, arguments, and member status. The `return` type in function overloads can now also be specified as a type signature string. PiperOrigin-RevId: 925627200
1 parent 76b61ae commit 06752e1

1 file changed

Lines changed: 30 additions & 51 deletions

File tree

cel_expr_python/cel_env_test.py

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,14 @@ def test_env_config_from_and_to_yaml(self):
7474
- name: "_+_"
7575
variables:
7676
- name: "one"
77-
type_name: "int"
77+
type: "int"
7878
value: 1
7979
functions:
8080
- name: "add"
8181
overloads:
8282
- id: "add_int_int"
83-
args:
84-
- type_name: "int"
85-
- type_name: "int"
86-
return:
87-
type_name: "int"
83+
signature: "add(int,int)"
84+
return: "int"
8885
"""),
8986
)
9087

@@ -139,9 +136,9 @@ def test_expression_container_abbreviations_and_aliases(self):
139136
qualified_name: "x.y.bar"
140137
variables:
141138
- name: "x.y.bar"
142-
type_name: "string"
139+
type: "string"
143140
- name: "x.y.foo"
144-
type_name: "int"
141+
type: "int"
145142
"""),
146143
)
147144

@@ -219,13 +216,13 @@ def test_abbreviations_and_aliases_combined(self):
219216
qualified_name: "a.b.qux"
220217
variables:
221218
- name: "a.b.baz"
222-
type_name: "int"
219+
type: "int"
223220
- name: "a.b.qux"
224-
type_name: "string"
221+
type: "string"
225222
- name: "x.y.bar"
226-
type_name: "string"
223+
type: "string"
227224
- name: "x.y.foo"
228-
type_name: "int"
225+
type: "int"
229226
"""),
230227
)
231228

@@ -275,48 +272,35 @@ def test_config_export_variables(self):
275272
normalize_yaml("""
276273
variables:
277274
- name: "var_bool"
278-
type_name: "bool"
275+
type: "bool"
279276
- name: "var_bytes"
280-
type_name: "bytes"
277+
type: "bytes"
281278
- name: "var_double"
282-
type_name: "double"
279+
type: "double"
283280
- name: "var_duration"
284-
type_name: "duration"
281+
type: "duration"
285282
- name: "var_dyn"
286-
type_name: "dyn"
283+
type: "dyn"
287284
- name: "var_dyn_list"
288-
type_name: "list"
289-
params:
290-
- type_name: "dyn"
285+
type: "list<dyn>"
291286
- name: "var_dyn_map"
292-
type_name: "map"
293-
params:
294-
- type_name: "dyn"
295-
- type_name: "dyn"
287+
type: "map<dyn,dyn>"
296288
- name: "var_int"
297-
type_name: "int"
289+
type: "int"
298290
- name: "var_int_map"
299-
type_name: "map"
300-
params:
301-
- type_name: "int"
302-
- type_name: "string"
291+
type: "map<int,string>"
303292
- name: "var_msg"
304-
type_name: "cel.expr.conformance.proto2.TestAllTypes"
293+
type: "cel.expr.conformance.proto2.TestAllTypes"
305294
- name: "var_str"
306-
type_name: "string"
295+
type: "string"
307296
- name: "var_string_list"
308-
type_name: "list"
309-
params:
310-
- type_name: "string"
297+
type: "list<string>"
311298
- name: "var_string_map"
312-
type_name: "map"
313-
params:
314-
- type_name: "string"
315-
- type_name: "bool"
299+
type: "map<string,bool>"
316300
- name: "var_timestamp"
317-
type_name: "timestamp"
301+
type: "timestamp"
318302
- name: "var_uint"
319-
type_name: "uint"
303+
type: "uint"
320304
"""),
321305
)
322306

@@ -338,9 +322,9 @@ def test_config_augmented_variables(self):
338322
normalize_yaml("""
339323
variables:
340324
- name: "var_bool"
341-
type_name: "bool"
325+
type: "bool"
342326
- name: "var_msg"
343-
type_name: "cel.expr.conformance.proto2.TestAllTypes"
327+
type: "cel.expr.conformance.proto2.TestAllTypes"
344328
"""),
345329
)
346330

@@ -554,18 +538,13 @@ def test_config_functions(self):
554538
- name: "hello"
555539
overloads:
556540
- id: "good_time_of_day"
557-
args:
558-
- type_name: "string"
559-
- type_name: "string"
560-
return:
561-
type_name: "string"
541+
signature: "hello(string,string)"
542+
return: "string"
562543
- name: "is_ok"
563544
overloads:
564545
- id: "is_ok_string"
565-
target:
566-
type_name: "string"
567-
return:
568-
type_name: "bool"
546+
signature: "string.is_ok()"
547+
return: "bool"
569548
"""),
570549
)
571550
res: cel.Value = env.compile("hello('am', 'Sunshine')").eval()

0 commit comments

Comments
 (0)