summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-03-30 17:23:52 +0200
committerbst-marge-bot <marge-bot@buildstream.build>2020-04-14 15:30:49 +0000
commit96430e2cf83ed0140968870e537494c130d43b7f (patch)
treeac7a33a5eb4c0054225fdb09791867c102432abe /src
parent3d5c183655221123501b206fa5be1d7d50bf3a4e (diff)
downloadbuildstream-96430e2cf83ed0140968870e537494c130d43b7f.tar.gz
node.pyx: MappingNode.get_int(): Support `None` as default
Diffstat (limited to 'src')
-rw-r--r--src/buildstream/node.pxd2
-rw-r--r--src/buildstream/node.pyx8
2 files changed, 6 insertions, 4 deletions
diff --git a/src/buildstream/node.pxd b/src/buildstream/node.pxd
index 47f46bbdf..c26d78a41 100644
--- a/src/buildstream/node.pxd
+++ b/src/buildstream/node.pxd
@@ -47,7 +47,7 @@ cdef class MappingNode(Node):
# Public Methods
cpdef bint get_bool(self, str key, default=*) except *
cpdef object get_enum(self, str key, object constraint, object default=*)
- cpdef int get_int(self, str key, default=*) except *
+ cpdef object get_int(self, str key, default=*)
cpdef MappingNode get_mapping(self, str key, default=*)
cpdef Node get_node(self, str key, list allowed_types=*, bint allow_none=*)
cpdef ScalarNode get_scalar(self, str key, default=*)
diff --git a/src/buildstream/node.pyx b/src/buildstream/node.pyx
index adc8aa04e..e33a11753 100644
--- a/src/buildstream/node.pyx
+++ b/src/buildstream/node.pyx
@@ -593,7 +593,7 @@ cdef class MappingNode(Node):
return (<ScalarNode> value).as_enum(constraint)
- cpdef int get_int(self, str key, object default=_sentinel) except *:
+ cpdef object get_int(self, str key, object default=_sentinel):
"""get_int(key, default=sentinel)
Get the value of the node for `key` as an integer.
@@ -602,7 +602,7 @@ cdef class MappingNode(Node):
Args:
key (str): key for which to get the value
- default (int): default value to return if `key` is not in the mapping
+ default (int, None): default value to return if `key` is not in the mapping
Raises:
:class:`buildstream._exceptions.LoadError`: if the value at `key` is not a
@@ -610,9 +610,11 @@ cdef class MappingNode(Node):
valid `integer`
Returns:
- :class:`int`: the value at `key` or the default
+ :class:`int` or :class:`None`: the value at `key` or the default
"""
cdef ScalarNode scalar = self.get_scalar(key, default)
+ if default is None and scalar.is_none():
+ return None
return scalar.as_int()
cpdef MappingNode get_mapping(self, str key, object default=_sentinel):