This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tristan/fix-boolean-parsing
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 8d8d9e71fa53117d3acd8731fb003e4b89195b00
Author: Tristan van Berkom <[email protected]>
AuthorDate: Wed May 21 18:26:12 2025 +0900

    node.pyx: Support loading 0/1 as boolean values
    
    It turns out that since OptionBool.get_value() is serializing boolean
    values as "0"/"1", we must support this in node parsing.
    
    This is because we should be able to use option value exporting
    to values, which can subsequently be specified in plugin configuration
    which wants to use MappingNode.get_bool().
    
    Fixes #2006
---
 src/buildstream/node.pyx | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/buildstream/node.pyx b/src/buildstream/node.pyx
index 2fc417c81..20fe70c8b 100644
--- a/src/buildstream/node.pyx
+++ b/src/buildstream/node.pyx
@@ -306,8 +306,8 @@ cdef class ScalarNode(Node):
     cpdef bint as_bool(self) except *:
         """Get the value of the node as a boolean.
 
-        .. note:: BuildStream treats the values 'True' and 'true' as True,
-                  and the values 'False' and 'false' as False.  Any other
+        .. note:: BuildStream treats the values 'True', 'true' and '1' as True,
+                  and the values 'False', 'false' and '0' as False.  Any other
                   string values (such as the valid YAML 'TRUE' or 'FALSE'
                   will be considered as an error)
 
@@ -322,9 +322,9 @@ cdef class ScalarNode(Node):
             return self.value
 
         # Don't coerce strings to booleans, this makes "False" strings 
evaluate to True
-        if self.value in ('True', 'true'):
+        if self.value in ('True', 'true', '1'):
             return True
-        elif self.value in ('False', 'false'):
+        elif self.value in ('False', 'false', '0'):
             return False
         else:
             provenance = self.get_provenance()

Reply via email to