Copilot commented on code in PR #3421:
URL: https://github.com/apache/iceberg-python/pull/3421#discussion_r3308945908
##########
pyiceberg/expressions/__init__.py:
##########
@@ -508,7 +508,7 @@ def as_unbound(self) -> type[UnboundPredicate]: ...
class UnboundPredicate(Unbound, BooleanExpression, ABC):
model_config = ConfigDict(arbitrary_types_allowed=True)
- term: UnboundTerm
+ term: Annotated[str | UnboundTerm, BeforeValidator(_to_unbound_term)]
Review Comment:
By annotating `term` as `str | UnboundTerm`, the model’s *post-validation
invariant* becomes unclear (and forces `type: ignore[union-attr]` where `term`
is used as an `UnboundTerm`). Since `_to_unbound_term` always returns an
`UnboundTerm` for `str` inputs, consider annotating the field as
`Annotated[UnboundTerm, BeforeValidator(_to_unbound_term)]` instead. This keeps
the runtime/validated type accurate, removes the need for the `union-attr`
ignores in `bind()`, and better communicates that `term.bind(...)` is always
valid after model construction.
##########
pyiceberg/expressions/__init__.py:
##########
@@ -696,7 +696,7 @@ def __init__(
super().__init__(term=_to_unbound_term(term), values=literal_set)
def bind(self, schema: Schema, case_sensitive: bool = True) ->
BoundSetPredicate:
- bound_term = self.term.bind(schema, case_sensitive)
+ bound_term = self.term.bind(schema, case_sensitive) # type:
ignore[union-attr]
Review Comment:
By annotating `term` as `str | UnboundTerm`, the model’s *post-validation
invariant* becomes unclear (and forces `type: ignore[union-attr]` where `term`
is used as an `UnboundTerm`). Since `_to_unbound_term` always returns an
`UnboundTerm` for `str` inputs, consider annotating the field as
`Annotated[UnboundTerm, BeforeValidator(_to_unbound_term)]` instead. This keeps
the runtime/validated type accurate, removes the need for the `union-attr`
ignores in `bind()`, and better communicates that `term.bind(...)` is always
valid after model construction.
##########
pyiceberg/expressions/__init__.py:
##########
@@ -540,7 +540,7 @@ def __str__(self) -> str:
return f"{str(self.__class__.__name__)}(term={str(self.term)})"
def bind(self, schema: Schema, case_sensitive: bool = True) ->
BoundUnaryPredicate:
- bound_term = self.term.bind(schema, case_sensitive)
+ bound_term = self.term.bind(schema, case_sensitive) # type:
ignore[union-attr]
Review Comment:
By annotating `term` as `str | UnboundTerm`, the model’s *post-validation
invariant* becomes unclear (and forces `type: ignore[union-attr]` where `term`
is used as an `UnboundTerm`). Since `_to_unbound_term` always returns an
`UnboundTerm` for `str` inputs, consider annotating the field as
`Annotated[UnboundTerm, BeforeValidator(_to_unbound_term)]` instead. This keeps
the runtime/validated type accurate, removes the need for the `union-attr`
ignores in `bind()`, and better communicates that `term.bind(...)` is always
valid after model construction.
##########
pyiceberg/expressions/__init__.py:
##########
@@ -870,7 +870,7 @@ def as_bound(self) -> type[BoundNotIn]: # type: ignore
class LiteralPredicate(UnboundPredicate, ABC):
type: TypingLiteral["lt", "lt-eq", "gt", "gt-eq", "eq", "not-eq",
"starts-with", "not-starts-with"] = Field(alias="type")
- term: UnboundTerm
+ term: Annotated[str | UnboundTerm, BeforeValidator(_to_unbound_term)]
Review Comment:
By annotating `term` as `str | UnboundTerm`, the model’s *post-validation
invariant* becomes unclear (and forces `type: ignore[union-attr]` where `term`
is used as an `UnboundTerm`). Since `_to_unbound_term` always returns an
`UnboundTerm` for `str` inputs, consider annotating the field as
`Annotated[UnboundTerm, BeforeValidator(_to_unbound_term)]` instead. This keeps
the runtime/validated type accurate, removes the need for the `union-attr`
ignores in `bind()`, and better communicates that `term.bind(...)` is always
valid after model construction.
##########
pyiceberg/expressions/__init__.py:
##########
@@ -885,7 +885,7 @@ def literal(self) -> LiteralValue:
return self.value
def bind(self, schema: Schema, case_sensitive: bool = True) ->
BoundLiteralPredicate:
- bound_term = self.term.bind(schema, case_sensitive)
+ bound_term = self.term.bind(schema, case_sensitive) # type:
ignore[union-attr]
Review Comment:
By annotating `term` as `str | UnboundTerm`, the model’s *post-validation
invariant* becomes unclear (and forces `type: ignore[union-attr]` where `term`
is used as an `UnboundTerm`). Since `_to_unbound_term` always returns an
`UnboundTerm` for `str` inputs, consider annotating the field as
`Annotated[UnboundTerm, BeforeValidator(_to_unbound_term)]` instead. This keeps
the runtime/validated type accurate, removes the need for the `union-attr`
ignores in `bind()`, and better communicates that `term.bind(...)` is always
valid after model construction.
--
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]