jaimeferj commented on code in PR #2561:
URL: https://github.com/apache/iceberg-python/pull/2561#discussion_r2440310543
##########
pyiceberg/expressions/__init__.py:
##########
@@ -743,12 +750,52 @@ def as_bound(self) -> Type[BoundNotIn[L]]:
return BoundNotIn[L]
-class LiteralPredicate(UnboundPredicate[L], ABC):
- literal: Literal[L]
+class LiteralPredicate(IcebergBaseModel, UnboundPredicate[L], ABC):
+ type: TypingLiteral["lt", "lt-eq", "gt", "gt-eq", "eq", "not-eq",
"starts-with", "not-starts-with"] = Field(alias="type")
+ term: UnboundTerm[Any]
+ value: Literal[L] = Field(alias="literal", serialization_alias="value")
+
+ model_config = ConfigDict(populate_by_name=True, frozen=True,
arbitrary_types_allowed=True)
+
+ def __init__(
+ self,
+ term: Union[str, UnboundTerm[Any], BoundReference[Any]],
+ literal: Union[L, Literal[L], None] = None,
+ **data: Any,
+ ) -> None: # pylint: disable=W0621
+ extra = dict(data)
+
+ literal_candidates = []
+ if literal is not None:
+ literal_candidates.append(literal)
+ if "literal" in extra:
+ literal_candidates.append(extra.pop("literal"))
+ if "value" in extra:
+ literal_candidates.append(extra.pop("value"))
+
+ literal_candidates = [candidate for candidate in literal_candidates if
candidate is not None]
+
+ if not literal_candidates:
+ raise TypeError("LiteralPredicate requires a literal or value
argument")
+ if len(literal_candidates) > 1:
+ raise TypeError("literal/value provided multiple times")
+
+ init = cast("Callable[..., None]", IcebergBaseModel.__init__)
+ init(self, term=_to_unbound_term(term),
literal=_to_literal(literal_candidates[0]), **extra)
+
+ @field_validator("term", mode="before")
+ @classmethod
+ def _convert_term(cls, value: Any) -> UnboundTerm[Any]:
+ return _to_unbound_term(value)
+
+ @field_validator("value", mode="before")
+ @classmethod
+ def _convert_value(cls, value: Any) -> Literal[Any]:
+ return _to_literal(value)
Review Comment:
Linter is not happy with that:
```
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1
pyiceberg/expressions/__init__.py:436: note: "__init__" of
"UnboundPredicate" defined here
pyiceberg/expressions/__init__.py:754: error: Unexpected keyword argument
"value" for "__init__" of "UnboundPredicate" [call-arg]
tests/expressions/test_expressions.py:433: error: Argument "term" to
"NotEqualTo" has incompatible type "BoundReference[str]"; expected "str |
UnboundTerm[Any]" [arg-type]
tests/expressions/test_expressions.py:440: error: Argument "term" to
"EqualTo" has incompatible type "BoundReference[str]"; expected "str |
UnboundTerm[Any]" [arg-type]
tests/expressions/test_expressions.py:450: error: Argument "term" to
"GreaterThanOrEqual" has incompatible type "BoundReference[str]"; expected "str
| UnboundTerm[Any]" [arg-type]
tests/expressions/test_expressions.py:457: error: Argument "term" to
"LessThan" has incompatible type "BoundReference[str]"; expected "str |
UnboundTerm[Any]" [arg-type]
tests/expressions/test_expressions.py:467: error: Argument "term" to
"LessThanOrEqual" has incompatible type "BoundReference[str]"; expected "str |
UnboundTerm[Any]" [arg-type]
tests/expressions/test_expressions.py:474: error: Argument "term" to
"GreaterThan" has incompatible type "BoundReference[str]"; expected "str |
UnboundTerm[Any]" [arg-type]
Found 7 errors in 2 files (checked 167 source files)```
--
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]