From dcfe2b182927019838c53e4add1376a69dabf4e6 Mon Sep 17 00:00:00 2001 From: CEL Dev Team Date: Tue, 7 Apr 2026 21:36:44 -0700 Subject: [PATCH] Add type stubs PiperOrigin-RevId: 896248449 --- cel_expr_python/BUILD | 3 +- cel_expr_python/cel.pyi | 77 ++++++++++++++++++++++++++++ cel_expr_python/ext/BUILD | 6 +++ cel_expr_python/ext/ext_bindings.pyi | 4 ++ cel_expr_python/ext/ext_encoders.pyi | 4 ++ cel_expr_python/ext/ext_math.pyi | 4 ++ cel_expr_python/ext/ext_optional.pyi | 4 ++ cel_expr_python/ext/ext_proto.pyi | 4 ++ cel_expr_python/ext/ext_strings.pyi | 4 ++ conformance/BUILD | 2 +- custom_ext/BUILD | 3 +- custom_ext/sample_cel_ext.pyi | 4 ++ 12 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 cel_expr_python/cel.pyi create mode 100644 cel_expr_python/ext/ext_bindings.pyi create mode 100644 cel_expr_python/ext/ext_encoders.pyi create mode 100644 cel_expr_python/ext/ext_math.pyi create mode 100644 cel_expr_python/ext/ext_optional.pyi create mode 100644 cel_expr_python/ext/ext_proto.pyi create mode 100644 cel_expr_python/ext/ext_strings.pyi create mode 100644 custom_ext/sample_cel_ext.pyi diff --git a/cel_expr_python/BUILD b/cel_expr_python/BUILD index aca5cc3..da05eef 100644 --- a/cel_expr_python/BUILD +++ b/cel_expr_python/BUILD @@ -1,6 +1,6 @@ load("@pybind11_bazel//:build_defs.bzl", "pybind_extension", "pybind_library") load("@rules_cc//cc:cc_library.bzl", "cc_library") -load("@rules_python//python:defs.bzl", "py_test") +load("@rules_python//python:py_test.bzl", "py_test") package(default_visibility = ["//visibility:private"]) @@ -45,6 +45,7 @@ pybind_extension( "py_message_factory.cc", "py_message_factory.h", ], + data = ["cel.pyi"], visibility = ["//visibility:public"], deps = [ ":cel_extension", diff --git a/cel_expr_python/cel.pyi b/cel_expr_python/cel.pyi new file mode 100644 index 0000000..db013bf --- /dev/null +++ b/cel_expr_python/cel.pyi @@ -0,0 +1,77 @@ +from collections.abc import Callable, Mapping, Sequence +import datetime +from typing import Any, ClassVar +from google.protobuf import descriptor_pool as proto_descriptor_pool +from google.protobuf import message as proto_message + +class Activation: pass + +class CelExtension(CelExtensionBase): + def __init__(self, name: str, functions: Sequence[FunctionDecl]) -> None: ... + +class CelExtensionBase: + def __init__(self, name: str) -> None: ... + +class Env: + def Activation(self, data: Mapping[str, Any] | None = ..., functions: Sequence[Function] | None = ..., arena: _InternalArena = ...) -> Activation: ... + def compile(self, expression: str, disable_check: bool = ...) -> Expression: ... + def deserialize(self, serialized: str) -> Expression: ... + +class Expression: + def eval(self, activation: Activation | None = ..., data: Mapping[str, Any] | None = ..., functions=..., arena: _InternalArena = ...) -> Value: ... + def return_type(self) -> Type: ... + def serialize(self) -> bytes: ... + +class Function: + def __init__(self, function_name: str, parameters: Sequence[Type], is_member: bool, impl: Callable[..., Any], return_type: Type = ...) -> None: ... + +class FunctionDecl: + def __init__(self, name: str, overloads: Sequence[Overload]) -> None: ... + +class Overload: + def __init__(self, overload_id: str, return_type: Type, parameters: Sequence[Type], is_member: bool = ..., impl: Callable[..., Any] = ...) -> None: ... + +class Type: + BOOL: ClassVar[Type] = ... + BYTES: ClassVar[Type] = ... + DOUBLE: ClassVar[Type] = ... + DURATION: ClassVar[Type] = ... + DYN: ClassVar[Type] = ... + ERROR: ClassVar[Type] = ... + INT: ClassVar[Type] = ... + LIST: ClassVar[Type] = ... + MAP: ClassVar[Type] = ... + NULL: ClassVar[Type] = ... + STRING: ClassVar[Type] = ... + TIMESTAMP: ClassVar[Type] = ... + TYPE: ClassVar[Type] = ... + UINT: ClassVar[Type] = ... + UNKNOWN: ClassVar[Type] = ... + def __init__(self, name: str) -> None: ... + @staticmethod + def AbstractType(name: str, params: Sequence[Type] = ...) -> Type: ... + @staticmethod + def List(element_type: Type) -> Type: ... + @staticmethod + def Map(key_type: Type, element_type: Type) -> Type: ... + @staticmethod + def Type(element_type: Type) -> Type: ... + def is_assignable_from(self, arg0: Type) -> bool: ... + def is_message(self) -> bool: ... + def name(self) -> str: ... + def __eq__(self, arg0: Type) -> bool: ... + +type BaseValue = None | bool | int | float | str | bytes | proto_message.Message | datetime.datetime | datetime.timedelta | Type +type PlainValue = BaseValue | list[PlainValue] | dict[PlainValue, PlainValue] +type CelValue = BaseValue | list[Value] | dict[PlainValue, Value] + +class Value: + def plain_value(self) -> PlainValue: ... + def type(self) -> Type: ... + def value(self) -> CelValue: ... + +class _InternalArena: pass + +def Arena() -> _InternalArena: ... + +def NewEnv(descriptor_pool: proto_descriptor_pool.DescriptorPool = ..., variables: Mapping[str, Type] | None = ..., extensions: Sequence[CelExtensionBase] | None = ..., container: str | None = ...) -> Env: ... diff --git a/cel_expr_python/ext/BUILD b/cel_expr_python/ext/BUILD index cdb038e..1e879c1 100644 --- a/cel_expr_python/ext/BUILD +++ b/cel_expr_python/ext/BUILD @@ -8,6 +8,7 @@ pybind_extension( "ext_bindings.cc", ], data = [ + "ext_bindings.pyi", "//cel_expr_python:cel", ], visibility = ["//visibility:public"], @@ -24,6 +25,7 @@ pybind_extension( "ext_encoders.cc", ], data = [ + "ext_encoders.pyi", "//cel_expr_python:cel", ], visibility = ["//visibility:public"], @@ -43,6 +45,7 @@ pybind_extension( "ext_math.cc", ], data = [ + "ext_math.pyi", "//cel_expr_python:cel", ], visibility = ["//visibility:public"], @@ -64,6 +67,7 @@ pybind_extension( "ext_optional.cc", ], data = [ + "ext_optional.pyi", "//cel_expr_python:cel", ], visibility = ["//visibility:public"], @@ -86,6 +90,7 @@ pybind_extension( "ext_proto.cc", ], data = [ + "ext_proto.pyi", "//cel_expr_python:cel", ], visibility = ["//visibility:public"], @@ -102,6 +107,7 @@ pybind_extension( "ext_strings.cc", ], data = [ + "ext_strings.pyi", "//cel_expr_python:cel", ], visibility = ["//visibility:public"], diff --git a/cel_expr_python/ext/ext_bindings.pyi b/cel_expr_python/ext/ext_bindings.pyi new file mode 100644 index 0000000..4b4c0f3 --- /dev/null +++ b/cel_expr_python/ext/ext_bindings.pyi @@ -0,0 +1,4 @@ +from cel_expr_python import cel + +class ExtBindings(cel.CelExtensionBase): + def __init__(self) -> None: ... diff --git a/cel_expr_python/ext/ext_encoders.pyi b/cel_expr_python/ext/ext_encoders.pyi new file mode 100644 index 0000000..33d7917 --- /dev/null +++ b/cel_expr_python/ext/ext_encoders.pyi @@ -0,0 +1,4 @@ +from cel_expr_python import cel + +class ExtEncoders(cel.CelExtensionBase): + def __init__(self) -> None: ... diff --git a/cel_expr_python/ext/ext_math.pyi b/cel_expr_python/ext/ext_math.pyi new file mode 100644 index 0000000..ae47f70 --- /dev/null +++ b/cel_expr_python/ext/ext_math.pyi @@ -0,0 +1,4 @@ +from cel_expr_python import cel + +class ExtMath(cel.CelExtensionBase): + def __init__(self) -> None: ... diff --git a/cel_expr_python/ext/ext_optional.pyi b/cel_expr_python/ext/ext_optional.pyi new file mode 100644 index 0000000..ecc291c --- /dev/null +++ b/cel_expr_python/ext/ext_optional.pyi @@ -0,0 +1,4 @@ +from cel_expr_python import cel + +class ExtOptional(cel.CelExtensionBase): + def __init__(self) -> None: ... diff --git a/cel_expr_python/ext/ext_proto.pyi b/cel_expr_python/ext/ext_proto.pyi new file mode 100644 index 0000000..b380ce8 --- /dev/null +++ b/cel_expr_python/ext/ext_proto.pyi @@ -0,0 +1,4 @@ +from cel_expr_python import cel + +class ExtProto(cel.CelExtensionBase): + def __init__(self) -> None: ... diff --git a/cel_expr_python/ext/ext_strings.pyi b/cel_expr_python/ext/ext_strings.pyi new file mode 100644 index 0000000..76fb4c2 --- /dev/null +++ b/cel_expr_python/ext/ext_strings.pyi @@ -0,0 +1,4 @@ +from cel_expr_python import cel + +class ExtStrings(cel.CelExtensionBase): + def __init__(self) -> None: ... diff --git a/conformance/BUILD b/conformance/BUILD index bed1210..0d3f090 100644 --- a/conformance/BUILD +++ b/conformance/BUILD @@ -1,4 +1,4 @@ -load("@rules_python//python:defs.bzl", "py_test") +load("@rules_python//python:py_test.bzl", "py_test") package(default_visibility = ["//visibility:private"]) diff --git a/custom_ext/BUILD b/custom_ext/BUILD index ae0d9d5..50762ca 100644 --- a/custom_ext/BUILD +++ b/custom_ext/BUILD @@ -1,6 +1,6 @@ load("@pybind11_bazel//:build_defs.bzl", "pybind_extension") -load("@rules_python//python:defs.bzl", "py_test") load("@rules_python//python:py_library.bzl", "py_library") +load("@rules_python//python:py_test.bzl", "py_test") package(default_visibility = ["//visibility:private"]) @@ -8,6 +8,7 @@ pybind_extension( name = "sample_cel_ext_cc", srcs = ["sample_cel_ext.cc"], data = [ + "sample_cel_ext.pyi", "//cel_expr_python:cel", ], deps = [ diff --git a/custom_ext/sample_cel_ext.pyi b/custom_ext/sample_cel_ext.pyi new file mode 100644 index 0000000..4ba20f9 --- /dev/null +++ b/custom_ext/sample_cel_ext.pyi @@ -0,0 +1,4 @@ +from cel_expr_python import cel + +class SampleCelExtension(cel.CelExtensionBase): + def __init__(self) -> None: ...