Skip to content

Commit

Permalink
Merge "[IMPR] return a boolean with item_is_in_list and item_has_label"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Nov 27, 2024
2 parents 09bdfb2 + 1f7b49b commit 71a9566
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions scripts/create_isbn_edition.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,39 +696,39 @@ def get_language_preferences() -> list[str]:
return main_languages


def item_is_in_list(statement_list: list, itemlist: list[str]) -> str:
def item_is_in_list(statement_list: list, itemlist: list[str]) -> bool:
"""Verify if statement list contains at least one item from the itemlist.
param statement_list: Statement list
param itemlist: List of values (string)
return: Matching or empty string
return: Whether the item matches
"""
for seq in statement_list:
with suppress(AttributeError): # Ignore NoneType error
isinlist = seq.getTarget().getID()
if isinlist in itemlist:
return isinlist
return ''
return True
return False


def item_has_label(item, label: str) -> str:
def item_has_label(item, label: str) -> bool:
"""Verify if the item has a label.
:param item: Item
:param label: Item label
:return: Matching string
:return: Whether the item has a label
"""
label = unidecode(label).casefold()
for lang in item.labels:
if unidecode(item.labels[lang]).casefold() == label:
return item.labels[lang]
return True

for lang in item.aliases:
for seq in item.aliases[lang]:
if unidecode(seq).casefold() == label:
return seq
return True

return '' # Must return "False" when no label
return False


def is_in_value_list(statement_list: list, valuelist: list[str]) -> bool:
Expand Down

0 comments on commit 71a9566

Please sign in to comment.