Copilot commented on code in PR #3917:
URL: https://github.com/apache/iceberg-python/pull/3917#discussion_r3946328403
##########
pyiceberg/expressions/parser.py:
##########
@@ -121,6 +121,16 @@ def _(result: ParseResults) -> Literal[bool]:
return BooleanLiteral(False)
+# As an operand a bare boolean has to fold to AlwaysTrue/AlwaysFalse. This
needs its own
+# copy because `literal` and `literal_set` keep the raw BooleanLiteral for
`foo = true`.
+always_boolean = boolean.copy()
+
+
+@always_boolean.add_parse_action
+def _(result: ParseResults) -> BooleanExpression:
+ return AlwaysTrue() if result[0].value else AlwaysFalse()
+
Review Comment:
`always_boolean` is created as a copy of `boolean`, which already has a
parse action returning a `BooleanLiteral`. Using `add_parse_action` here means
both parse actions run, creating an intermediate `BooleanLiteral` only to
immediately discard it, and it also couples this folding logic to
`BooleanLiteral.value`. Consider overriding the parse action on the copy
instead (so only one parse action runs and it depends only on the raw token).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]