diff --git a/python/src/iceberg/transforms.py b/python/src/iceberg/transforms.py index 7945210ec0b2..3ebc19219bb9 100644 --- a/python/src/iceberg/transforms.py +++ b/python/src/iceberg/transforms.py @@ -64,10 +64,10 @@ def __repr__(self): def __str__(self): return self._transform_string - def __call__(self, value: S) -> Optional[T]: + def __call__(self, value: Optional[S]) -> Optional[T]: return self.apply(value) - def apply(self, value: S) -> Optional[T]: + def apply(self, value: Optional[S]) -> Optional[T]: ... def can_transform(self, source: IcebergType) -> bool: @@ -83,10 +83,8 @@ def preserves_order(self) -> bool: def satisfies_order_of(self, other) -> bool: return self == other - def to_human_string(self, value) -> str: - if value is None: - return "null" - return str(value) + def to_human_string(self, value: Optional[S]) -> str: + return str(value) if value is not None else "null" @property def dedup_name(self) -> str: @@ -119,11 +117,8 @@ def num_buckets(self) -> int: def hash(self, value: S) -> int: raise NotImplementedError() - def apply(self, value: S) -> Optional[int]: - if value is None: - return None - - return (self.hash(value) & IntegerType.max) % self._num_buckets + def apply(self, value: Optional[S]) -> Optional[int]: + return (self.hash(value) & IntegerType.max) % self._num_buckets if value else None def result_type(self, source: IcebergType) -> IcebergType: return IntegerType() diff --git a/python/tox.ini b/python/tox.ini index 92757798b6ac..8be70e957c48 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -69,7 +69,7 @@ commands = deps = mypy commands = - mypy --no-implicit-optional --install-types --non-interactive --config tox.ini src + mypy --install-types --non-interactive --config tox.ini src [testenv:docs] basepython = python3 @@ -97,5 +97,11 @@ python = 3.8: py38, linters 3.9: py39 +[mypy] + +no_implicit_optional=True +warn_redundant_casts=True +warn_unreachable=True + [mypy-pyarrow.*] ignore_missing_imports = True