diff mbox series

[2.2,1/4] utils: Allow to_boolean to support int values

Message ID 20230310204519.706973-1-Martin.Jansa@gmail.com
State New
Headers show
Series [2.2,1/4] utils: Allow to_boolean to support int values | expand

Commit Message

Martin Jansa March 10, 2023, 8:45 p.m. UTC
From: Richard Purdie <richard.purdie@linuxfoundation.org>

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.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/utils.py | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 3ce98d317..2f6d9229a 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -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