1616# under the License.
1717from __future__ import annotations
1818
19- from collections .abc import Iterable , Iterator , MutableSet
19+ from collections .abc import Iterable , Iterator , Set
2020from dataclasses import dataclass
21- from typing import Any
2221
2322from pyiceberg .manifest import DataFile
2423
@@ -41,15 +40,15 @@ def from_file(cls, delete_file: DataFile) -> DeleteFileKey:
4140 )
4241
4342
44- class DeleteFileSet (MutableSet [DataFile ]):
45- """Set-like delete-file collection keyed by location and content range."""
43+ class DeleteFileSet (Set [DataFile ]):
44+ """Read-only delete-file collection keyed by location and content range."""
4645
4746 _files : dict [DeleteFileKey , DataFile ]
4847
4948 def __init__ (self , delete_files : Iterable [DataFile ] = ()) -> None :
5049 self ._files = {}
5150 for delete_file in delete_files :
52- self .add ( delete_file )
51+ self ._files . setdefault ( DeleteFileKey . from_file ( delete_file ), delete_file )
5352
5453 def __contains__ (self , delete_file : object ) -> bool :
5554 """Return whether the delete file is present."""
@@ -63,34 +62,25 @@ def __len__(self) -> int:
6362 """Return the number of delete files."""
6463 return len (self ._files )
6564
66- def add (self , delete_file : DataFile ) -> None :
67- self ._files .setdefault (DeleteFileKey .from_file (delete_file ), delete_file )
68-
69- def discard (self , delete_file : DataFile ) -> None :
70- self ._files .pop (DeleteFileKey .from_file (delete_file ), None )
71-
72- def update (self , delete_files : Iterable [DataFile ]) -> None :
73- for delete_file in delete_files :
74- self .add (delete_file )
75-
7665 def __repr__ (self ) -> str :
7766 """Return a string representation of the delete file set."""
7867 return f"{ type (self ).__name__ } ({ list (self )!r} )"
7968
80- def __eq__ (self , other : Any ) -> bool :
69+ def __eq__ (self , other : object ) -> bool :
8170 """Compare delete file sets by delete file identity."""
8271 if isinstance (other , DeleteFileSet ):
8372 return self ._files .keys () == other ._files .keys ()
8473
85- if not isinstance (other , Iterable ):
74+ if not isinstance (other , Set ):
75+ return NotImplemented
76+
77+ if len (self ) != len (other ):
8678 return False
8779
8880 other_keys : set [DeleteFileKey ] = set ()
89- other_count = 0
9081 for delete_file in other :
9182 if not isinstance (delete_file , DataFile ):
9283 return False
9384 other_keys .add (DeleteFileKey .from_file (delete_file ))
94- other_count += 1
9585
96- return len ( other_keys ) == other_count and set ( self ._files ) == other_keys
86+ return self ._files . keys ( ) == other_keys
0 commit comments