refactor: fix component recursion (#936)

This commit is contained in:
Juro Oravec 2025-02-01 17:19:21 +01:00 committed by GitHub
parent e105500350
commit 588053803d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 1549 additions and 464 deletions

View file

@ -24,13 +24,6 @@ def gen_id() -> str:
)
def find_last_index(lst: List, predicate: Callable[[Any], bool]) -> Any:
for r_idx, elem in enumerate(reversed(lst)):
if predicate(elem):
return len(lst) - 1 - r_idx
return -1
def is_str_wrapped_in_quotes(s: str) -> bool:
return s.startswith(('"', "'")) and s[0] == s[-1] and len(s) >= 2
@ -66,7 +59,16 @@ def default(val: Optional[T], default: T) -> T:
return val if val is not None else default
def get_index(lst: List, key: Callable[[Any], bool]) -> Optional[int]:
"""Get the index of the first item in the list that satisfies the key"""
for i in range(len(lst)):
if key(lst[i]):
return i
return None
def get_last_index(lst: List, key: Callable[[Any], bool]) -> Optional[int]:
"""Get the index of the last item in the list that satisfies the key"""
for index, item in enumerate(reversed(lst)):
if key(item):
return len(lst) - 1 - index