@@ -106,8 +106,7 @@ def __init__(self, ctx: Context, path: str, pathinfo: str = "", uid: str = "guid
106106 self ._uid = uid
107107 self ._cache : Optional [List [T ]] = None
108108
109- @property
110- def _data (self ) -> List [T ]:
109+ def _get_or_fetch (self ) -> List [T ]:
111110 """
112111 Fetch and cache the data from the API.
113112
@@ -142,16 +141,20 @@ def __getitem__(self, index: int) -> T: ...
142141 def __getitem__ (self , index : slice ) -> Sequence [T ]: ...
143142
144143 def __getitem__ (self , index ):
145- return self ._data [index ]
144+ data = self ._get_or_fetch ()
145+ return data [index ]
146146
147147 def __len__ (self ) -> int :
148- return len (self ._data )
148+ data = self ._get_or_fetch ()
149+ return len (data )
149150
150151 def __str__ (self ) -> str :
151- return str (self ._data )
152+ data = self ._get_or_fetch ()
153+ return str (data )
152154
153155 def __repr__ (self ) -> str :
154- return repr (self ._data )
156+ data = self ._get_or_fetch ()
157+ return repr (data )
155158
156159 @abstractmethod
157160 def _create_instance (self , path : str , pathinfo : str , / , ** kwargs : Any ) -> T :
@@ -226,4 +229,5 @@ def find_by(self, **conditions: Any) -> Optional[T]:
226229 Optional[T]
227230 The first record matching the conditions, or `None` if no match is found.
228231 """
229- return next ((v for v in self ._data if v .items () >= conditions .items ()), None )
232+ data = self ._get_or_fetch ()
233+ return next ((v for v in data if v .items () >= conditions .items ()), None )
0 commit comments