Skip to content

Commit 6cf0111

Browse files
committed
Fix mypy: cast dict-key lookups back to TableVersion
max() and list indexing on the version-keyed schema dicts widen the Literal[1, 2, 3] TableVersion back to int, so mypy flags the results as incompatible with the declared TableVersion return types.
1 parent 338632b commit 6cf0111

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎pyiceberg/manifest.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from typing import (
2727
Any,
2828
Literal,
29+
cast,
2930
)
3031

3132
from cachetools import LRUCache
@@ -802,8 +803,8 @@ def construct_partition_summaries(spec: PartitionSpec, schema: Schema, partition
802803
# schema dicts, so each has its own latest-version constant rather than sharing one. Note these are
803804
# intentionally separate from DEFAULT_READ_VERSION, which remains the default layout for constructing
804805
# and writing records.
805-
LATEST_MANIFEST_ENTRY_READ_VERSION: TableVersion = max(MANIFEST_ENTRY_SCHEMAS)
806-
LATEST_MANIFEST_LIST_READ_VERSION: TableVersion = max(MANIFEST_LIST_FILE_SCHEMAS)
806+
LATEST_MANIFEST_ENTRY_READ_VERSION: TableVersion = cast(TableVersion, max(MANIFEST_ENTRY_SCHEMAS))
807+
LATEST_MANIFEST_LIST_READ_VERSION: TableVersion = cast(TableVersion, max(MANIFEST_LIST_FILE_SCHEMAS))
807808

808809

809810
def _layout_version_from_field_count(layouts: Mapping[int, Schema | StructType], field_count: int) -> TableVersion:
@@ -823,7 +824,7 @@ def _layout_version_from_field_count(layouts: Mapping[int, Schema | StructType],
823824
raise ValueError(f"Ambiguous layout: versions {matches} all have {field_count} fields")
824825
if not matches:
825826
raise ValueError(f"Cannot determine layout version for record with {field_count} fields")
826-
return matches[0]
827+
return cast(TableVersion, matches[0])
827828

828829

829830
POSITIONAL_DELETE_SCHEMA = Schema(

0 commit comments

Comments
 (0)