Skip to content

Commit 482f4e0

Browse files
committed
fix: use type in main class only and remove __op__
1 parent c1f7384 commit 482f4e0

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

pyiceberg/expressions/__init__.py

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717

1818
from __future__ import annotations
1919

20-
import typing
2120
from abc import ABC, abstractmethod
2221
from functools import cached_property
2322
from typing import (
2423
Any,
2524
Callable,
26-
ClassVar,
2725
Generic,
2826
Iterable,
2927
Sequence,
@@ -35,9 +33,7 @@
3533
)
3634
from typing import Literal as TypingLiteral
3735

38-
from pydantic import Field
39-
40-
from pydantic import ConfigDict, Field, field_serializer, field_validator
36+
from pydantic import ConfigDict, Field, field_serializer
4137

4238
from pyiceberg.expressions.literals import (
4339
AboveMax,
@@ -748,29 +744,15 @@ def as_bound(self) -> Type[BoundNotIn[L]]:
748744

749745

750746
class LiteralPredicate(IcebergBaseModel, UnboundPredicate[L], ABC):
751-
op: str = Field(
752-
default="",
753-
alias="type",
754-
validation_alias="type",
755-
serialization_alias="type",
756-
repr=False,
757-
)
747+
type: TypingLiteral["lt-eq", "gt", "gt-eq", "eq", "not-eq", "starts-with", "not-starts-with"] = Field(alias="type")
758748
term: Term[L]
759749
literal: Literal[L] = Field(serialization_alias="value")
760750

761-
__op__: ClassVar[str] = ""
762-
763751
model_config = ConfigDict(arbitrary_types_allowed=True)
764752

765753
def __init__(self, term: Union[str, UnboundTerm[Any]], literal: Union[L, Literal[L]]): # pylint: disable=W0621
766754
super().__init__(term=_to_unbound_term(term), literal=_to_literal(literal))
767755

768-
def model_post_init(self, __context: Any) -> None:
769-
if not self.op:
770-
object.__setattr__(self, "op", self.__op__)
771-
elif self.op != self.__op__:
772-
raise ValueError(f"Invalid type {self.op!r}; expected {self.__op__!r}")
773-
774756
@field_serializer("term")
775757
def ser_term(self, v: Term[L]) -> str:
776758
return v.name
@@ -919,7 +901,7 @@ def as_unbound(self) -> Type[NotStartsWith[L]]:
919901

920902

921903
class EqualTo(LiteralPredicate[L]):
922-
__op__ = "eq"
904+
type: TypingLiteral["eq"] = Field(default="eq", alias="type")
923905

924906
def __invert__(self) -> NotEqualTo[L]:
925907
"""Transform the Expression into its negated version."""
@@ -931,7 +913,7 @@ def as_bound(self) -> Type[BoundEqualTo[L]]:
931913

932914

933915
class NotEqualTo(LiteralPredicate[L]):
934-
__op__ = "not-eq"
916+
type: TypingLiteral["not-eq"] = Field(default="not-eq", alias="type")
935917

936918
def __invert__(self) -> EqualTo[L]:
937919
"""Transform the Expression into its negated version."""
@@ -943,7 +925,7 @@ def as_bound(self) -> Type[BoundNotEqualTo[L]]:
943925

944926

945927
class LessThan(LiteralPredicate[L]):
946-
__op__ = "lt"
928+
type: TypingLiteral["lt"] = Field(default="lt", alias="type")
947929

948930
def __invert__(self) -> GreaterThanOrEqual[L]:
949931
"""Transform the Expression into its negated version."""
@@ -955,7 +937,7 @@ def as_bound(self) -> Type[BoundLessThan[L]]:
955937

956938

957939
class GreaterThanOrEqual(LiteralPredicate[L]):
958-
__op__ = "gt-eq"
940+
type: TypingLiteral["gt-eq"] = Field(default="gt-eq", alias="type")
959941

960942
def __invert__(self) -> LessThan[L]:
961943
"""Transform the Expression into its negated version."""
@@ -967,7 +949,7 @@ def as_bound(self) -> Type[BoundGreaterThanOrEqual[L]]:
967949

968950

969951
class GreaterThan(LiteralPredicate[L]):
970-
__op__ = "gt"
952+
type: TypingLiteral["gt"] = Field(default="gt", alias="type")
971953

972954
def __invert__(self) -> LessThanOrEqual[L]:
973955
"""Transform the Expression into its negated version."""
@@ -979,7 +961,7 @@ def as_bound(self) -> Type[BoundGreaterThan[L]]:
979961

980962

981963
class LessThanOrEqual(LiteralPredicate[L]):
982-
__op__ = "lt-eq"
964+
type: TypingLiteral["lt-eq"] = Field(default="lt-eq", alias="type")
983965

984966
def __invert__(self) -> GreaterThan[L]:
985967
"""Transform the Expression into its negated version."""
@@ -991,7 +973,7 @@ def as_bound(self) -> Type[BoundLessThanOrEqual[L]]:
991973

992974

993975
class StartsWith(LiteralPredicate[L]):
994-
__op__ = "starts-with"
976+
type: TypingLiteral["starts-with"] = Field(default="starts-with", alias="type")
995977

996978
def __invert__(self) -> NotStartsWith[L]:
997979
"""Transform the Expression into its negated version."""
@@ -1003,7 +985,7 @@ def as_bound(self) -> Type[BoundStartsWith[L]]:
1003985

1004986

1005987
class NotStartsWith(LiteralPredicate[L]):
1006-
__op__ = "not-starts-with"
988+
type: TypingLiteral["not-starts-with"] = Field(default="not-starts-with", alias="type")
1007989

1008990
def __invert__(self) -> StartsWith[L]:
1009991
"""Transform the Expression into its negated version."""

0 commit comments

Comments
 (0)