Repository navigation
[Python] Support direct equality comparison on cel.Value. - #127
Merged
Merged
Conversation
copybara-service
Bot
force-pushed
the
test_1015986905
branch
from
November 7, 2026 02:46
44f247e to
dfad430
Compare
cel.Value.
copybara-service
Bot
force-pushed
the
test_1015986905
branch
2 times, most recently
from
November 10, 2026 22:20
fed218b to
4a12980
Compare
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
Bot
force-pushed
the
test_1015986905
branch
from
November 10, 2026 22:25
4a12980 to
75352be
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[Python] Support direct equality comparison on
cel.Value.Define
__eq__onPyCelValue(cel.Value, inherited by_CelListItemAccessorand_CelMapItemAccessor) by delegating toPyObject_RichCompareon the lazily resolved Python value, unwrapping theright-hand side when comparing two
cel.Valueinstances while keepingERRORvalues distinct from plain
str/STRINGcel.Values andBOOLvaluesdistinct from numeric types. Also mark
PyCelType's__eq__binding withpy::is_operator()so comparingcel.Typeagainst non-Typeobjects returnsNotImplementedinstead of raisingTypeError.This allows
expr.eval()andexpr.eval().value()(including lists, maps, andindexed elements) to be compared directly against plain Python values (e.g.
assertEqual(expr.eval(), [0, 1, 2])) without requiringplain_value().