Skip to contentSkip to conversation

utils: Allow to_boolean to support int values

PATCH New Richard Purdie 1 participant 1 message Nov 24, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils: Allow to_boolean to support int values

Some variables may be set as:

X = 1

as well the more usual

X = "1"

so add support to to_boolean to handle this case.

---
 lib/bb/utils.py | 3 +++
 1 file changed, 3 insertions(+)
lib/bb/utils.py +3 -0
index 64a004d0d8..f4da356338 100644
@@ -992,6 +992,9 @@ def to_boolean(string, default=None):
     if not string:
         return default
 
+    if isinstance(string, int):
+        return string != 0
+
     normalized = string.lower()
     if normalized in ("y", "yes", "1", "true"):
         return True
Signature · 1 line
2.34.1