diff options
author | Jürg Billeter <j@bitron.ch> | 2020-03-30 17:23:52 +0200 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2020-04-14 15:30:49 +0000 |
commit | 96430e2cf83ed0140968870e537494c130d43b7f (patch) | |
tree | ac7a33a5eb4c0054225fdb09791867c102432abe /src/buildstream/node.pyx | |
parent | 3d5c183655221123501b206fa5be1d7d50bf3a4e (diff) | |
download | buildstream-96430e2cf83ed0140968870e537494c130d43b7f.tar.gz |
node.pyx: MappingNode.get_int(): Support `None` as default
Diffstat (limited to 'src/buildstream/node.pyx')
-rw-r--r-- | src/buildstream/node.pyx | 8 |
1 files changed, 5 insertions, 3 deletions
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): |