jaimeferj commented on code in PR #2561:
URL: https://github.com/apache/iceberg-python/pull/2561#discussion_r2422212804
##########
pyiceberg/expressions/__init__.py:
##########
@@ -743,12 +749,33 @@ 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[L]
+ literal: Literal[L] = Field(serialization_alias="value")
+
+ model_config = ConfigDict(arbitrary_types_allowed=True)
+
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
+ if args:
+ if len(args) != 2:
+ raise TypeError("Expected (term, literal)")
+ kwargs = {"term": args[0], "literal": args[1], **kwargs}
+ super().__init__(**kwargs)
Review Comment:
After having many issues with an __init__ such as:
```Python
def __init__(self, term: Union[str, UnboundTerm[Any]], literals:
Union[Iterable[L], Iterable[Literal[L]]]):
super().__init__(term=_to_unbound_term(term),
items=_to_literal_set(literals))
```
Because there are some typing errors with `_transform_literal` in
`pyiceberg/transforms.py` for example:
```
pyiceberg/transforms.py:1113: error: Argument 1 to "_transform_literal"
has incompatible type "Callable[[str | None], str | None]"; expected
"Callable[[str], str]" [arg-type]
pyiceberg/transforms.py:1113: error: Argument 1 to "_transform_literal"
has incompatible type "Callable[[bool | None], bool | None]"; expected
"Callable[[str], str]" [arg-type]
pyiceberg/transforms.py:1113: error: Argument 1 to "_transform_literal"
has incompatible type "Callable[[int | None], int | None]"; expected
"Callable[[str], str]" [arg-type]
pyiceberg/transforms.py:1113: error: Argument 1 to "_transform_literal"
has incompatible type "Callable[[float | None], float | None]"; expected
"Callable[[str], str]" [arg-type]
pyiceberg/transforms.py:1113: error: Argument 1 to "_transform_literal"
has incompatible type "Callable[[bytes | None], bytes | None]"; expected
"Callable[[str], str]" [arg-type]
pyiceberg/transforms.py:1113: error: Argument 1 to "_transform_literal"
has incompatible type "Callable[[UUID | None], UUID | None]"; expected
"Callable[[str], str]" [arg-type]
```
I decided to just go for this implementation of __init__. The problem now is
that:
```Python
assert_type(EqualTo("a", "b"), EqualTo[str]) # <-- Fails
------
tests/expressions/test_expressions.py:1238: error: Expression is of type
"LiteralPredicate[L]", not "EqualTo[str]" [assert-type]
```
So I am really stuck, would you mind lending a hand here? @Fokko
--
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]