Skip to content

[Python] Support direct equality comparison on cel.Value. - #127

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_1015986905
Nov 10, 2026
Merged

copybara-service[bot] merged 1 commit into
mainfrom
test_1015986905

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

[Python] Support direct equality comparison on cel.Value.

Define __eq__ on PyCelValue (cel.Value, inherited by
_CelListItemAccessor and _CelMapItemAccessor) by delegating to
PyObject_RichCompare on the lazily resolved Python value, unwrapping the
right-hand side when comparing two cel.Value instances while keeping ERROR
values distinct from plain str / STRING cel.Values and BOOL values
distinct from numeric types. Also mark PyCelType's __eq__ binding with
py::is_operator() so comparing cel.Type against non-Type objects returns
NotImplemented instead of raising TypeError.

This allows expr.eval() and expr.eval().value() (including lists, maps, and
indexed elements) to be compared directly against plain Python values (e.g.
assertEqual(expr.eval(), [0, 1, 2])) without requiring plain_value().

@copybara-service copybara-service Bot changed the title [Python] Support equality comparison on list and map item accessors. [Python] Support direct equality comparison on cel.Value. Nov 7, 2026
@copybara-service
copybara-service Bot force-pushed the test_1015986905 branch 2 times, most recently from fed218b to 4a12980 Compare November 10, 2026 22:20
Define `__eq__` on `PyCelValue` (`cel.Value`, inherited by
`_CelListItemAccessor` and `_CelMapItemAccessor`) by delegating to
`PyObject_RichCompare` on the lazily resolved Python value, unwrapping the
right-hand side when comparing two `cel.Value` instances while keeping `ERROR`
values distinct from plain `str` / `STRING` `cel.Value`s and `BOOL` values
distinct from numeric types. Also mark `PyCelType`'s `__eq__` binding with
`py::is_operator()` so comparing `cel.Type` against non-`Type` objects returns
`NotImplemented` instead of raising `TypeError`.

This allows `expr.eval()` and `expr.eval().value()` (including lists, maps, and
indexed elements) to be compared directly against plain Python values (e.g.
`assertEqual(expr.eval(), [0, 1, 2])`) without requiring `plain_value()`.

PiperOrigin-RevId: 1018550229
@copybara-service
copybara-service Bot merged commit 75352be into main Nov 10, 2026
1 check passed
@copybara-service
copybara-service Bot deleted the test_1015986905 branch November 10, 2026 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant