3737from pyiceberg .io import FileIO , InputFile , OutputFile
3838from pyiceberg .partitioning import PartitionSpec
3939from pyiceberg .schema import Schema
40- from pyiceberg .typedef import EMPTY_DICT , Record
40+ from pyiceberg .typedef import EMPTY_DICT , Record , TableVersion
4141from pyiceberg .types import (
4242 BinaryType ,
4343 BooleanType ,
@@ -302,7 +302,7 @@ def _(partition_field_type: PrimitiveType) -> PrimitiveType:
302302 return partition_field_type
303303
304304
305- def data_file_with_partition (partition_type : StructType , format_version : Literal [ 1 , 2 ] ) -> StructType :
305+ def data_file_with_partition (partition_type : StructType , format_version : TableVersion ) -> StructType :
306306 data_file_partition_type = StructType (* [
307307 NestedField (
308308 field_id = field .field_id ,
@@ -372,7 +372,7 @@ def __setattr__(self, name: str, value: Any) -> None:
372372 value = FileFormat [value ]
373373 super ().__setattr__ (name , value )
374374
375- def __init__ (self , format_version : Literal [ 1 , 2 ] = DEFAULT_READ_VERSION , * data : Any , ** named_data : Any ) -> None :
375+ def __init__ (self , format_version : TableVersion = DEFAULT_READ_VERSION , * data : Any , ** named_data : Any ) -> None :
376376 super ().__init__ (
377377 * data ,
378378 ** {"struct" : DATA_FILE_TYPE [format_version ], ** named_data },
@@ -408,7 +408,7 @@ def __eq__(self, other: Any) -> bool:
408408MANIFEST_ENTRY_SCHEMAS_STRUCT = {format_version : schema .as_struct () for format_version , schema in MANIFEST_ENTRY_SCHEMAS .items ()}
409409
410410
411- def manifest_entry_schema_with_data_file (format_version : Literal [ 1 , 2 ] , data_file : StructType ) -> Schema :
411+ def manifest_entry_schema_with_data_file (format_version : TableVersion , data_file : StructType ) -> Schema :
412412 return Schema (* [
413413 NestedField (2 , "data_file" , data_file , required = True ) if field .field_id == 2 else field
414414 for field in MANIFEST_ENTRY_SCHEMAS [format_version ].fields
@@ -719,9 +719,9 @@ def content(self) -> ManifestContent: ...
719719
720720 @property
721721 @abstractmethod
722- def version (self ) -> Literal [ 1 , 2 ] : ...
722+ def version (self ) -> TableVersion : ...
723723
724- def _with_partition (self , format_version : Literal [ 1 , 2 ] ) -> Schema :
724+ def _with_partition (self , format_version : TableVersion ) -> Schema :
725725 data_file_type = data_file_with_partition (
726726 format_version = format_version , partition_type = self ._spec .partition_type (self ._schema )
727727 )
@@ -807,7 +807,7 @@ def content(self) -> ManifestContent:
807807 return ManifestContent .DATA
808808
809809 @property
810- def version (self ) -> Literal [ 1 , 2 ] :
810+ def version (self ) -> TableVersion :
811811 return 1
812812
813813 def prepare_entry (self , entry : ManifestEntry ) -> ManifestEntry :
@@ -834,7 +834,7 @@ def content(self) -> ManifestContent:
834834 return ManifestContent .DATA
835835
836836 @property
837- def version (self ) -> Literal [ 1 , 2 ] :
837+ def version (self ) -> TableVersion :
838838 return 2
839839
840840 def prepare_entry (self , entry : ManifestEntry ) -> ManifestEntry :
@@ -847,7 +847,7 @@ def prepare_entry(self, entry: ManifestEntry) -> ManifestEntry:
847847
848848
849849def write_manifest (
850- format_version : Literal [ 1 , 2 ] , spec : PartitionSpec , schema : Schema , output_file : OutputFile , snapshot_id : int
850+ format_version : TableVersion , spec : PartitionSpec , schema : Schema , output_file : OutputFile , snapshot_id : int
851851) -> ManifestWriter :
852852 if format_version == 1 :
853853 return ManifestWriterV1 (spec , schema , output_file , snapshot_id )
@@ -858,14 +858,14 @@ def write_manifest(
858858
859859
860860class ManifestListWriter (ABC ):
861- _format_version : Literal [ 1 , 2 ]
861+ _format_version : TableVersion
862862 _output_file : OutputFile
863863 _meta : Dict [str , str ]
864864 _manifest_files : List [ManifestFile ]
865865 _commit_snapshot_id : int
866866 _writer : AvroOutputFile [ManifestFile ]
867867
868- def __init__ (self , format_version : Literal [ 1 , 2 ] , output_file : OutputFile , meta : Dict [str , Any ]):
868+ def __init__ (self , format_version : TableVersion , output_file : OutputFile , meta : Dict [str , Any ]):
869869 self ._format_version = format_version
870870 self ._output_file = output_file
871871 self ._meta = meta
@@ -957,7 +957,7 @@ def prepare_manifest(self, manifest_file: ManifestFile) -> ManifestFile:
957957
958958
959959def write_manifest_list (
960- format_version : Literal [ 1 , 2 ] ,
960+ format_version : TableVersion ,
961961 output_file : OutputFile ,
962962 snapshot_id : int ,
963963 parent_snapshot_id : Optional [int ],
0 commit comments