Skip to content

Commit cccb370

Browse files
committed
update: reduce code and supress errors
1 parent 35c83c7 commit cccb370

File tree

1 file changed

+4
-39
lines changed

1 file changed

+4
-39
lines changed

pyiceberg/expressions/__init__.py

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@
3030
Type,
3131
TypeVar,
3232
Union,
33-
cast,
3433
)
3534
from typing import Literal as TypingLiteral
3635

37-
from pydantic import ConfigDict, Field, field_validator
36+
from pydantic import Field
3837

3938
from pyiceberg.expressions.literals import (
4039
AboveMax,
@@ -753,45 +752,11 @@ def as_bound(self) -> Type[BoundNotIn[L]]:
753752
class LiteralPredicate(IcebergBaseModel, UnboundPredicate[L], ABC):
754753
type: TypingLiteral["lt", "lt-eq", "gt", "gt-eq", "eq", "not-eq", "starts-with", "not-starts-with"] = Field(alias="type")
755754
term: UnboundTerm[Any]
756-
value: Literal[L] = Field(alias="literal", serialization_alias="value")
757-
755+
value: Literal[L] = Field()
758756
model_config = ConfigDict(populate_by_name=True, frozen=True, arbitrary_types_allowed=True)
759757

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]
795760

796761
@property
797762
def literal(self) -> Literal[L]:

0 commit comments

Comments
 (0)