Skip to content

Commit 1365378

Browse files
fix: remove lru_cache from instance method and add lint to catch future issues (#1883)
`@lru_cache` on an instance method causes the cache to ref the instance, which causes a reference loop that can't be GC'd. We could make a `weakref_self_lru_cache` for this purpose, but a `getattr` guard is simple enough
1 parent e34fc4d commit 1365378

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

python/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ torch = [
6464
]
6565

6666
[tool.ruff]
67-
select = ["F", "E", "W", "I", "G", "TCH", "PERF", "CPY001"]
67+
select = ["F", "E", "W", "I", "G", "TCH", "PERF", "CPY001", "B019"]
6868

6969
[tool.mypy]
7070
python_version = "3.11"

python/python/lance/dataset.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from abc import ABC, abstractmethod
2424
from dataclasses import dataclass
2525
from datetime import datetime, timedelta
26-
from functools import lru_cache
2726
from pathlib import Path
2827
from typing import (
2928
TYPE_CHECKING,
@@ -114,9 +113,10 @@ def uri(self) -> str:
114113
"""
115114
return self._uri
116115

117-
@lru_cache(maxsize=None)
118116
def list_indices(self) -> List[Dict[str, Any]]:
119-
return self._ds.load_indices()
117+
if getattr(self, "_list_indices_res", None) is None:
118+
self._list_indices_res = self._ds.load_indices()
119+
return self._list_indices_res
120120

121121
def index_statistics(self, index_name: str) -> Dict[str, Any]:
122122
warnings.warn(

0 commit comments

Comments
 (0)