From 96430e2cf83ed0140968870e537494c130d43b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Mon, 30 Mar 2020 17:23:52 +0200 Subject: node.pyx: MappingNode.get_int(): Support `None` as default --- src/buildstream/node.pxd | 2 +- src/buildstream/node.pyx | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src') 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 ( 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): -- cgit v1.2.1