Skip to content

Commit 3ed3b2b

Browse files
committed
fix: Expose cache_clear method for _manifests function
- Create explicit cache instance for _manifests - Add cache_clear attribute to enable cache clearing in tests - Remove type: ignore comment as cache_clear is now properly exposed - Fixes CI/CD mypy unused-ignore error
1 parent e308212 commit 3ed3b2b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pyiceberg/manifest.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,13 +876,22 @@ def __hash__(self) -> int:
876876
return hash(self.manifest_path)
877877

878878

879-
@cached(cache=LRUCache(maxsize=128), key=lambda io, manifest_list: hashkey(manifest_list), lock=threading.RLock())
879+
# Create cache instance for _manifests function
880+
_manifests_cache: LRUCache[Tuple[str, str], Tuple[ManifestFile, ...]] = LRUCache(maxsize=128)
881+
_manifests_lock = threading.RLock()
882+
883+
884+
@cached(cache=_manifests_cache, key=lambda io, manifest_list: hashkey(manifest_list), lock=_manifests_lock)
880885
def _manifests(io: FileIO, manifest_list: str) -> Tuple[ManifestFile, ...]:
881886
"""Read and cache manifests from the given manifest list, returning a tuple to prevent modification."""
882887
file = io.new_input(manifest_list)
883888
return tuple(read_manifest_list(file))
884889

885890

891+
# Expose cache_clear method for testing
892+
_manifests.cache_clear = _manifests_cache.clear # type: ignore[attr-defined]
893+
894+
886895
def read_manifest_list(input_file: InputFile) -> Iterator[ManifestFile]:
887896
"""
888897
Read the manifests from the manifest list.

tests/utils/test_manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
@pytest.fixture(autouse=True)
4949
def clear_global_manifests_cache() -> None:
5050
# Clear the global cache before each test
51-
_manifests.cache_clear() # type: ignore[attr-defined]
51+
_manifests.cache_clear()
5252

5353

5454
def _verify_metadata_with_fastavro(avro_file: str, expected_metadata: Dict[str, str]) -> None:

0 commit comments

Comments
 (0)