jaimeferj commented on code in PR #2565:
URL: https://github.com/apache/iceberg-python/pull/2565#discussion_r2443525050
##########
pyiceberg/expressions/__init__.py:
##########
@@ -302,12 +302,19 @@ def __getnewargs__(self) -> Tuple[BooleanExpression,
BooleanExpression]:
return (self.left, self.right)
-class Or(BooleanExpression):
+class Or(IcebergBaseModel, BooleanExpression):
"""OR operation expression - logical disjunction."""
+ model_config = ConfigDict(arbitrary_types_allowed=True)
+
+ type: TypingLiteral["str"] = Field(default="or", alias="type")
left: BooleanExpression
right: BooleanExpression
+ def __init__(self, left: BooleanExpression, right: BooleanExpression,
*rest: BooleanExpression) -> None:
+ if isinstance(self, Or) and not hasattr(self, "left") and not
hasattr(self, "right"):
+ super().__init__(left=left, right=right)
+
Review Comment:
This weird `__init__` is to make sure that if the class has been already
initialized in `__new__`, it is not initialized again.
If this is not made, multiple things can happen:
- If *rest is given, although `_build_balanced_tree` build an `Or` instance
correctly, Python would call again `Or` initializer with the original
parameters `left` and `right` resulting in `Or(left, right)`, ignoring the
created `Or` instance from `_build_balanced_tree`
- If left or right is `AlwaysTrue` it will get overriden and the instance
will be initialized as `Or(left, right)`
- If left and right is `AlwaysFalse` it will get overriden and the instance
will be initialized as `Or(left, right)`
I do not know why exactly but it gotta be something from Pydantic
--
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]