jaimeferj commented on code in PR #2561:
URL: https://github.com/apache/iceberg-python/pull/2561#discussion_r2404697013
##########
pyiceberg/expressions/__init__.py:
##########
@@ -725,12 +729,37 @@ def as_bound(self) -> Type[BoundNotIn[L]]:
return BoundNotIn[L]
-class LiteralPredicate(UnboundPredicate[L], ABC):
- literal: Literal[L]
+class LiteralPredicate(IcebergBaseModel, UnboundPredicate[L], ABC):
+ op: str = Field(
+ default="",
+ alias="type",
+ validation_alias="type",
+ serialization_alias="type",
+ repr=False,
+ )
Review Comment:
One solution might be doing something like this:
```Python
class LiteralPredicateOp(str, Enum):
LT = "lt"
LT_EQ = "lt-eq"
EQ = "eq"
GT_EQ = "gt-eq"
GT = "gt"
NOT_EQ = "not-eq"
STARTS_WITH = "starts-with"
NOT_STARTS_WITH = "not-starts-with"
class LiteralPredicate(IcebergBaseModel, UnboundPredicate[L], ABC):
type: LiteralPredicateOp
_type: ClassVar[LiteralPredicateOp]
term: Term[L]
literal: Literal[L] = Field(serialization_alias="value")
@model_validator(mode="before")
@classmethod
def _inject(cls, v):
if isinstance(v, dict) and "type" not in v and hasattr(cls, "_type"):
v = dict(v)
v["type"] = cls._type
return v
```
And the implementations:
```Python
class EqualTo(LiteralPredicate[L]):
_type: ClassVar[LiteralPredicateOp] = LiteralPredicateOp.EQ
```
That way mypy is happy and the developer will understand it easily
--
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]