jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1093597?usp=email )
Change subject: [IMPR] return a boolean with item_is_in_list and item_has_label
......................................................................
[IMPR] return a boolean with item_is_in_list and item_has_label
Simplify the code: both functions are used with their boolean result,
it is not necessary to return the item found.
Change-Id: Ie7e38f8fa041e91b8cca7c7dec813b1236beb2ae
---
M scripts/create_isbn_edition.py
1 file changed, 9 insertions(+), 9 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/create_isbn_edition.py b/scripts/create_isbn_edition.py
index d803761..79d5d85 100755
--- a/scripts/create_isbn_edition.py
+++ b/scripts/create_isbn_edition.py
@@ -696,39 +696,39 @@
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:
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1093597?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ie7e38f8fa041e91b8cca7c7dec813b1236beb2ae
Gerrit-Change-Number: 1093597
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Geertivp <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]