@@ -125,15 +125,12 @@ def get_run_id_from_name(
125125 """
126126 _runs = Run .get (filters = json .dumps ([f"name == { name } " ]))
127127
128- try :
129- _id , _ = next (_runs )
130- except StopIteration as e :
131- raise RuntimeError (
132- "Could not collect ID - no run found with this name."
133- ) from e
128+ if not (_first_entry := next (_runs , None )):
129+ raise RuntimeError ("Could not collect ID - no run found with this name." )
134130
135- with contextlib .suppress (StopIteration ):
136- next (_runs )
131+ _id , _ = _first_entry
132+
133+ if next (_runs , None ):
137134 raise RuntimeError (
138135 "Could not collect ID - more than one run exists with this name."
139136 )
@@ -325,11 +322,9 @@ def _get_folder_from_path(self, path: str) -> Folder | None:
325322 """
326323 _folders = Folder .get (filters = json .dumps ([f"path == { path } " ]))
327324
328- try :
329- _ , _folder = next (_folders )
330- return _folder # type: ignore
331- except StopIteration :
332- return None
325+ _ , _folder = next (_folders , (None , None ))
326+
327+ return _folder
333328
334329 def _get_folder_id_from_path (self , path : str ) -> str | None :
335330 """Retrieve folder identifier for the specified path if found
@@ -346,13 +341,10 @@ def _get_folder_id_from_path(self, path: str) -> str | None:
346341 """
347342 _ids = Folder .ids (filters = json .dumps ([f"path == { path } " ]))
348343
349- try :
350- _id = next (_ids )
351- except StopIteration :
344+ if not (_id := next (_ids , None )):
352345 return None
353346
354- with contextlib .suppress (StopIteration ):
355- next (_ids )
347+ if next (_ids , None ):
356348 raise RuntimeError (
357349 f"Expected single folder match for '{ path } ', but found duplicate."
358350 )
0 commit comments