aashish-g03 commented on code in PR #3421:
URL: https://github.com/apache/iceberg-python/pull/3421#discussion_r3308968380


##########
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:
   Thanks for the suggestion. I considered `Annotated[UnboundTerm, 
BeforeValidator(_to_unbound_term)]` first, but it does not fix the issue.
   
   Without the pydantic mypy plugin (which this project does not use), mypy 
generates `__init__` signatures from the outer `Annotated` type. So 
`Annotated[UnboundTerm, ...]` still produces:
   
   ```
   error: Argument "term" has incompatible type "str"; expected "UnboundTerm"  
[arg-type]
   ```
   
   I verified this with a minimal repro — only `str | UnboundTerm` as the outer 
type makes mypy accept `str` in the constructor without the plugin. The `type: 
ignore[union-attr]` on the 3 `bind()` calls is the trade-off, but the validator 
guarantees the runtime type is always `UnboundTerm`.



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

Reply via email to