jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1337973?usp=email )

Change subject: tools: Replace strtobool value checks with constant mapping
......................................................................

tools: Replace strtobool value checks with constant mapping

Change-Id: I47680b3277b6693ffe88cdb867e511749c4e47ff
---
M pywikibot/tools/__init__.py
1 file changed, 20 insertions(+), 5 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index b696713..7e8b55b 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -387,6 +387,22 @@
     return re.sub(f'[{pattern}]', repl, string)


+_STR_TO_BOOL = {
+    'y': True,
+    'yes': True,
+    't': True,
+    'true': True,
+    'on': True,
+    '1': True,
+    'n': False,
+    'no': False,
+    'f': False,
+    'false': False,
+    'off': False,
+    '0': False,
+}
+
+
 def strtobool(val: str) -> bool:
     """Convert a string representation of truth to True or False.

@@ -411,11 +427,10 @@
     :raises ValueError: `val` is not a valid truth value
     """
     val = val.lower()
-    if val in ('y', 'yes', 't', 'true', 'on', '1'):
-        return True
-    if val in ('n', 'no', 'f', 'false', 'off', '0'):
-        return False
-    raise ValueError(f'invalid truth value {val!r}')
+    try:
+        return _STR_TO_BOOL[val]
+    except KeyError:
+        raise ValueError(f'invalid truth value {val!r}')


 def normalize_username(username) -> str | None:

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1337973?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: I47680b3277b6693ffe88cdb867e511749c4e47ff
Gerrit-Change-Number: 1337973
Gerrit-PatchSet: 4
Gerrit-Owner: Mahveotm <[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]

Reply via email to