Skip to content

Commit 516d120

Browse files
committed
Replace type: ignore with isinstance assertions in bind() methods
Address review feedback: instead of adding type: ignore[union-attr] comments, use isinstance assertions to narrow the type. This satisfies mypy through type narrowing while also documenting the invariant that term is always UnboundTerm after validator coercion.
1 parent 6b81682 commit 516d120

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎pyiceberg/expressions/__init__.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,8 @@ def __str__(self) -> str:
540540
return f"{str(self.__class__.__name__)}(term={str(self.term)})"
541541

542542
def bind(self, schema: Schema, case_sensitive: bool = True) -> BoundUnaryPredicate:
543-
bound_term = self.term.bind(schema, case_sensitive) # type: ignore[union-attr]
543+
assert isinstance(self.term, UnboundTerm)
544+
bound_term = self.term.bind(schema, case_sensitive)
544545
bound_type = self.as_bound
545546
return bound_type(bound_term) # type: ignore[misc]
546547

@@ -696,7 +697,8 @@ def __init__(
696697
super().__init__(term=_to_unbound_term(term), values=literal_set)
697698

698699
def bind(self, schema: Schema, case_sensitive: bool = True) -> BoundSetPredicate:
699-
bound_term = self.term.bind(schema, case_sensitive) # type: ignore[union-attr]
700+
assert isinstance(self.term, UnboundTerm)
701+
bound_term = self.term.bind(schema, case_sensitive)
700702
literal_set = self.literals
701703
return self.as_bound(bound_term, {lit.to(bound_term.ref().field.field_type) for lit in literal_set}) # type: ignore
702704

@@ -885,7 +887,8 @@ def literal(self) -> LiteralValue:
885887
return self.value
886888

887889
def bind(self, schema: Schema, case_sensitive: bool = True) -> BoundLiteralPredicate:
888-
bound_term = self.term.bind(schema, case_sensitive) # type: ignore[union-attr]
890+
assert isinstance(self.term, UnboundTerm)
891+
bound_term = self.term.bind(schema, case_sensitive)
889892
lit = self.literal.to(bound_term.ref().field.field_type)
890893

891894
if isinstance(lit, AboveMax):

0 commit comments

Comments
 (0)