Skip to content

Commit 00bc5db

Browse files
committed
fix: use type in main class only and remove __op__
1 parent 2ebc03d commit 00bc5db

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

pyiceberg/expressions/__init__.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
TypeVar,
3434
Union,
3535
)
36+
from typing import Literal as TypingLiteral
3637

3738
from pydantic import ConfigDict, Field, field_serializer, field_validator
3839

@@ -730,29 +731,15 @@ def as_bound(self) -> Type[BoundNotIn[L]]:
730731

731732

732733
class LiteralPredicate(IcebergBaseModel, UnboundPredicate[L], ABC):
733-
op: str = Field(
734-
default="",
735-
alias="type",
736-
validation_alias="type",
737-
serialization_alias="type",
738-
repr=False,
739-
)
734+
type: TypingLiteral["lt-eq", "gt", "gt-eq", "eq", "not-eq", "starts-with", "not-starts-with"] = Field(alias="type")
740735
term: Term[L]
741736
literal: Literal[L] = Field(serialization_alias="value")
742737

743-
__op__: ClassVar[str] = ""
744-
745738
model_config = ConfigDict(arbitrary_types_allowed=True)
746739

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

750-
def model_post_init(self, __context: Any) -> None:
751-
if not self.op:
752-
object.__setattr__(self, "op", self.__op__)
753-
elif self.op != self.__op__:
754-
raise ValueError(f"Invalid type {self.op!r}; expected {self.__op__!r}")
755-
756743
@field_serializer("term")
757744
def ser_term(self, v: Term[L]) -> str:
758745
return v.name
@@ -901,7 +888,7 @@ def as_unbound(self) -> Type[NotStartsWith[L]]:
901888

902889

903890
class EqualTo(LiteralPredicate[L]):
904-
__op__ = "eq"
891+
type: TypingLiteral["eq"] = Field(default="eq", alias="type")
905892

906893
def __invert__(self) -> NotEqualTo[L]:
907894
"""Transform the Expression into its negated version."""
@@ -913,7 +900,7 @@ def as_bound(self) -> Type[BoundEqualTo[L]]:
913900

914901

915902
class NotEqualTo(LiteralPredicate[L]):
916-
__op__ = "not-eq"
903+
type: TypingLiteral["not-eq"] = Field(default="not-eq", alias="type")
917904

918905
def __invert__(self) -> EqualTo[L]:
919906
"""Transform the Expression into its negated version."""
@@ -925,7 +912,7 @@ def as_bound(self) -> Type[BoundNotEqualTo[L]]:
925912

926913

927914
class LessThan(LiteralPredicate[L]):
928-
__op__ = "lt"
915+
type: TypingLiteral["lt"] = Field(default="lt", alias="type")
929916

930917
def __invert__(self) -> GreaterThanOrEqual[L]:
931918
"""Transform the Expression into its negated version."""
@@ -937,7 +924,7 @@ def as_bound(self) -> Type[BoundLessThan[L]]:
937924

938925

939926
class GreaterThanOrEqual(LiteralPredicate[L]):
940-
__op__ = "gt-eq"
927+
type: TypingLiteral["gt-eq"] = Field(default="gt-eq", alias="type")
941928

942929
def __invert__(self) -> LessThan[L]:
943930
"""Transform the Expression into its negated version."""
@@ -949,7 +936,7 @@ def as_bound(self) -> Type[BoundGreaterThanOrEqual[L]]:
949936

950937

951938
class GreaterThan(LiteralPredicate[L]):
952-
__op__ = "gt"
939+
type: TypingLiteral["gt"] = Field(default="gt", alias="type")
953940

954941
def __invert__(self) -> LessThanOrEqual[L]:
955942
"""Transform the Expression into its negated version."""
@@ -961,7 +948,7 @@ def as_bound(self) -> Type[BoundGreaterThan[L]]:
961948

962949

963950
class LessThanOrEqual(LiteralPredicate[L]):
964-
__op__ = "lt-eq"
951+
type: TypingLiteral["lt-eq"] = Field(default="lt-eq", alias="type")
965952

966953
def __invert__(self) -> GreaterThan[L]:
967954
"""Transform the Expression into its negated version."""
@@ -973,7 +960,7 @@ def as_bound(self) -> Type[BoundLessThanOrEqual[L]]:
973960

974961

975962
class StartsWith(LiteralPredicate[L]):
976-
__op__ = "starts-with"
963+
type: TypingLiteral["starts-with"] = Field(default="starts-with", alias="type")
977964

978965
def __invert__(self) -> NotStartsWith[L]:
979966
"""Transform the Expression into its negated version."""
@@ -985,7 +972,7 @@ def as_bound(self) -> Type[BoundStartsWith[L]]:
985972

986973

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

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

0 commit comments

Comments
 (0)