Fokko commented on code in PR #6139:
URL: https://github.com/apache/iceberg/pull/6139#discussion_r1023219441


##########
python/pyiceberg/expressions/__init__.py:
##########
@@ -48,12 +65,13 @@ class Bound(ABC):
     """Represents a bound value expression"""
 
 
-class Unbound(Generic[B], ABC):
+class Unbound(ABC):
     """Represents an unbound value expression"""
 
+    @property
     @abstractmethod
-    def bind(self, schema: Schema, case_sensitive: bool = True) -> B:
-        ...  # pragma: no cover
+    def as_bound(self) -> Type[Bound]:
+        ...
 
 
 class BoundTerm(Term[T], Bound, ABC):

Review Comment:
   There is one final issue that we need to tackle. Now the Literals have all 
types and work fine, unfortunately, the BoundTerm T is initialized to 
`<nothing>`:
   
   ```
   ➜  python git:(fd-remove-dataclass) ✗ pre-commit run --all-files mypy
   
mypy.....................................................................Failed
   - hook id: mypy
   - exit code: 1
   
   python/tests/expressions/test_visitors.py:330: error: Argument 2 to "In" has 
incompatible type "Set[Literal[str]]"; expected "Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:331: error: Argument 2 to "In" has 
incompatible type "Set[Literal[int]]"; expected "Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:339: error: Argument 2 to 
"BoundIn" has incompatible type "Set[Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:346: error: Argument 2 to 
"BoundIn" has incompatible type "Set[Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:352: error: Argument 2 to "In" has 
incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:355: error: Argument 2 to "In" has 
incompatible type "Tuple[Literal[int]]"; expected "Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:359: error: Argument 2 to "In" has 
incompatible type "Tuple[Literal[str]]"; expected "Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:369: error: Argument 2 to 
"BoundIn" has incompatible type "Set[Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:376: error: Argument 2 to 
"BoundEqualTo" has incompatible type "Literal[int]"; expected 
"Literal[<nothing>]"
   python/tests/expressions/test_visitors.py:384: error: Argument 2 to 
"BoundEqualTo" has incompatible type "Literal[str]"; expected 
"Literal[<nothing>]"
   python/tests/expressions/test_visitors.py:401: error: Argument 2 to "In" has 
incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:402: error: Argument 2 to "In" has 
incompatible type "Tuple[Literal[int], Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:410: error: Argument 2 to 
"BoundIn" has incompatible type "Set[Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:417: error: Argument 2 to 
"BoundIn" has incompatible type "Set[Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:423: error: Argument 2 to "In" has 
incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:426: error: Argument 2 to "In" has 
incompatible type "Tuple[Literal[str]]"; expected "Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:430: error: Argument 2 to "In" has 
incompatible type "Tuple[Literal[str]]"; expected "Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:440: error: Argument 2 to 
"BoundIn" has incompatible type "Set[Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:447: error: Argument 2 to 
"BoundIn" has incompatible type "Set[Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:455: error: Argument 2 to 
"BoundIn" has incompatible type "Set[Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:492: error: Argument 2 to "In" has 
incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:498: error: Argument 2 to 
"BoundIn" has incompatible type "Set[Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:502: error: Argument 2 to "In" has 
incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:508: error: Argument 2 to 
"BoundIn" has incompatible type "Set[Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:514: error: Argument 2 to "In" has 
incompatible type "Tuple[Literal[str]]"; expected "Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:521: error: Argument 2 to 
"BoundEqualTo" has incompatible type "Literal[str]"; expected 
"Literal[<nothing>]"
   python/tests/expressions/test_visitors.py:536: error: Argument 2 to "In" has 
incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:543: error: Argument 2 to 
"BoundIn" has incompatible type "Set[Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:550: error: Argument 2 to "In" has 
incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:551: error: Argument 2 to "In" has 
incompatible type "Tuple[Literal[str], Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:561: error: Argument 2 to 
"BoundIn" has incompatible type "Set[Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:568: error: Argument 2 to 
"BoundIn" has incompatible type "Set[Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1301: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1305: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1309: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1313: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1317: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1321: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1325: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1329: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1333: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1337: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1343: error: Argument 2 to "NotIn" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1347: error: Argument 2 to "NotIn" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1351: error: Argument 2 to "NotIn" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1355: error: Argument 2 to "NotIn" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1359: error: Argument 2 to "NotIn" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1363: error: Argument 2 to "NotIn" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1367: error: Argument 2 to "NotIn" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1371: error: Argument 2 to "NotIn" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1375: error: Argument 2 to "NotIn" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_visitors.py:1379: error: Argument 2 to "NotIn" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:228: error: Argument "literal" 
to "BoundNotEqualTo" has incompatible type "Literal[str]"; expected 
"Literal[<nothing>]"
   python/tests/expressions/test_expressions.py:263: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:273: error: Argument 2 to 
"BoundNotIn" has incompatible type "Set[Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:284: error: Argument 2 to 
"BoundIn" has incompatible type "Set[Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:293: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[str], Literal[str], Literal[str]]"; 
expected "Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:300: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:312: error: Argument "literal" 
to "BoundNotEqualTo" has incompatible type "Literal[str]"; expected 
"Literal[<nothing>]"
   python/tests/expressions/test_expressions.py:325: error: Argument "literal" 
to "BoundEqualTo" has incompatible type "Literal[str]"; expected 
"Literal[<nothing>]"
   python/tests/expressions/test_expressions.py:338: error: Argument "literal" 
to "BoundLessThan" has incompatible type "Literal[str]"; expected 
"Literal[<nothing>]"
   python/tests/expressions/test_expressions.py:351: error: Argument "literal" 
to "BoundLessThanOrEqual" has incompatible type "Literal[str]"; expected 
"Literal[<nothing>]"
   python/tests/expressions/test_expressions.py:364: error: Argument "literal" 
to "BoundGreaterThanOrEqual" has incompatible type "Literal[str]"; expected 
"Literal[<nothing>]"
   python/tests/expressions/test_expressions.py:377: error: Argument "literal" 
to "BoundGreaterThan" has incompatible type "Literal[str]"; expected 
"Literal[<nothing>]"
   python/tests/expressions/test_expressions.py:435: error: Argument 2 to 
"NotIn" has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:453: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:454: error: Argument 2 to 
"NotIn" has incompatible type "Tuple[Literal[int], Literal[int]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:486: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:487: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:488: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:491: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:492: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:493: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:517: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:518: error: Argument 2 to 
"NotIn" has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:521: error: Argument 2 to 
"NotIn" has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   python/tests/expressions/test_expressions.py:522: error: Argument 2 to "In" 
has incompatible type "Tuple[Literal[str], Literal[str]]"; expected 
"Iterable[Literal[<nothing>]]"
   Found 77 errors in 2 files (checked 83 source files)
   ```
   
   The issue is that the `BoundTerm` is initialized first, and it has nothing 
to bind to, therefore it is a `Nothing`. Then it goes to the second argument 
and finds out that the Literal has a different type (string, int etc). The 
problem is that we don't have any information available for the `BoundTerm` 
since `mypy` is a static type checker.
   
   @rdblue asked a similar question yesterday with respect to the Unbound type: 
https://github.com/apache/iceberg/pull/6139#discussion_r1022540353 My 
suggestion is to remove `T` from unbound, and add it to the 
`BoundLiteralPredicate` and `BoundSetPredicate` so we just use the types of the 
literals for now.



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