Skip to content

Commit 321c5b6

Browse files
committed
Make And expression JSON serializable using Pydantic
1 parent 6f71f21 commit 321c5b6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pyiceberg/expressions/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,15 @@ def as_bound(self) -> Type[BoundReference[L]]:
253253
class And(IcebergBaseModel, BooleanExpression):
254254
"""AND operation expression - logical conjunction."""
255255

256-
model_config = ConfigDict(arbitrary_types_allowed=True, frozen=False)
256+
model_config = ConfigDict(arbitrary_types_allowed=True)
257257

258258
type: TypingLiteral["and"] = Field(default="and", alias="type")
259259
left: BooleanExpression
260260
right: BooleanExpression
261261

262262
def __init__(self, left: BooleanExpression, right: BooleanExpression, *rest: BooleanExpression) -> None:
263-
super().__init__(left=left, right=right)
263+
if isinstance(self, And) and not hasattr(self, "left") and not hasattr(self, "right"):
264+
super().__init__(left=left, right=right)
264265

265266
def __new__(cls, left: BooleanExpression, right: BooleanExpression, *rest: BooleanExpression) -> BooleanExpression: # type: ignore
266267
if rest:
@@ -284,7 +285,7 @@ def __eq__(self, other: Any) -> bool:
284285

285286
def __str__(self) -> str:
286287
"""Return the string representation of the And class."""
287-
return f"And(left={str(self.left)}, right={str(self.right)})"
288+
return f"{str(self.__class__.__name__)}(left={repr(self.left)}, right={repr(self.right)})"
288289

289290
def __repr__(self) -> str:
290291
"""Return the string representation of the And class."""

0 commit comments

Comments
 (0)