|
30 | 30 | Type, |
31 | 31 | TypeVar, |
32 | 32 | Union, |
33 | | - cast, |
34 | 33 | ) |
35 | 34 | from typing import Literal as TypingLiteral |
36 | 35 |
|
37 | | -from pydantic import ConfigDict, Field, field_validator |
| 36 | +from pydantic import Field |
38 | 37 |
|
39 | 38 | from pyiceberg.expressions.literals import ( |
40 | 39 | AboveMax, |
@@ -753,45 +752,11 @@ def as_bound(self) -> Type[BoundNotIn[L]]: |
753 | 752 | class LiteralPredicate(IcebergBaseModel, UnboundPredicate[L], ABC): |
754 | 753 | type: TypingLiteral["lt", "lt-eq", "gt", "gt-eq", "eq", "not-eq", "starts-with", "not-starts-with"] = Field(alias="type") |
755 | 754 | term: UnboundTerm[Any] |
756 | | - value: Literal[L] = Field(alias="literal", serialization_alias="value") |
757 | | - |
| 755 | + value: Literal[L] = Field() |
758 | 756 | model_config = ConfigDict(populate_by_name=True, frozen=True, arbitrary_types_allowed=True) |
759 | 757 |
|
760 | | - def __init__( |
761 | | - self, |
762 | | - term: Union[str, UnboundTerm[Any], BoundReference[Any]], |
763 | | - literal: Union[L, Literal[L], None] = None, |
764 | | - **data: Any, |
765 | | - ) -> None: # pylint: disable=W0621 |
766 | | - extra = dict(data) |
767 | | - |
768 | | - literal_candidates = [] |
769 | | - if literal is not None: |
770 | | - literal_candidates.append(literal) |
771 | | - if "literal" in extra: |
772 | | - literal_candidates.append(extra.pop("literal")) |
773 | | - if "value" in extra: |
774 | | - literal_candidates.append(extra.pop("value")) |
775 | | - |
776 | | - literal_candidates = [candidate for candidate in literal_candidates if candidate is not None] |
777 | | - |
778 | | - if not literal_candidates: |
779 | | - raise TypeError("LiteralPredicate requires a literal or value argument") |
780 | | - if len(literal_candidates) > 1: |
781 | | - raise TypeError("literal/value provided multiple times") |
782 | | - |
783 | | - init = cast("Callable[..., None]", IcebergBaseModel.__init__) |
784 | | - init(self, term=_to_unbound_term(term), literal=_to_literal(literal_candidates[0]), **extra) |
785 | | - |
786 | | - @field_validator("term", mode="before") |
787 | | - @classmethod |
788 | | - def _convert_term(cls, value: Any) -> UnboundTerm[Any]: |
789 | | - return _to_unbound_term(value) |
790 | | - |
791 | | - @field_validator("value", mode="before") |
792 | | - @classmethod |
793 | | - def _convert_value(cls, value: Any) -> Literal[Any]: |
794 | | - return _to_literal(value) |
| 758 | + def __init__(self, term: Union[str, UnboundTerm[Any], BoundReference[Any]], literal: Union[L, Literal[L]]): |
| 759 | + super().__init__(term=_to_unbound_term(term), value=_to_literal(literal)) # type: ignore[call-arg] |
795 | 760 |
|
796 | 761 | @property |
797 | 762 | def literal(self) -> Literal[L]: |
|
0 commit comments