From 504ecb3e4fff2e0c7e28550cbf6d26dbffe1a07c Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Fri, 7 Dec 2018 16:55:01 +0900 Subject: plugin.py: Added new `allow_none` parameter to Plugin.node_get_member(), defaulting to False. Allow plugins to conveniently leverage the new `allow_none` parameter, and have Plugin.node_get_member() raise a LoadError in the usual case where None is not an acceptable value to be explicitly set in the user provided YAML. --- buildstream/plugin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/buildstream/plugin.py b/buildstream/plugin.py index 1e8dd4b9f..2f51c8807 100644 --- a/buildstream/plugin.py +++ b/buildstream/plugin.py @@ -323,7 +323,7 @@ class Plugin(): provenance = _yaml.node_get_provenance(node, key=member_name) return str(provenance) - def node_get_member(self, node, expected_type, member_name, default=_yaml._sentinel): + def node_get_member(self, node, expected_type, member_name, default=_yaml._sentinel, *, allow_none=False): """Fetch the value of a node member, raising an error if the value is missing or incorrectly typed. @@ -332,6 +332,7 @@ class Plugin(): expected_type (type): The expected type of the node member member_name (str): The name of the member to fetch default (expected_type): A value to return when *member_name* is not specified in *node* + allow_none (bool): Allow explicitly set None values in the YAML (*Since: 1.4*) Returns: The value of *member_name* in *node*, otherwise *default* @@ -352,7 +353,7 @@ class Plugin(): # Fetch an optional integer level = self.node_get_member(node, int, 'level', -1) """ - return _yaml.node_get(node, expected_type, member_name, default_value=default) + return _yaml.node_get(node, expected_type, member_name, default_value=default, allow_none=allow_none) def node_get_project_path(self, node, key, *, check_is_file=False, check_is_dir=False): -- cgit v1.2.1