diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-12-07 16:55:01 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-12-07 16:57:56 +0900 |
commit | 504ecb3e4fff2e0c7e28550cbf6d26dbffe1a07c (patch) | |
tree | fa7b2a3f4a91a564ec1a15ef6f82629db6acb6f0 /buildstream/plugin.py | |
parent | e61e6e50b74813f7a50f8c3a66f54b6682a427b8 (diff) | |
download | buildstream-504ecb3e4fff2e0c7e28550cbf6d26dbffe1a07c.tar.gz |
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.
Diffstat (limited to 'buildstream/plugin.py')
-rw-r--r-- | buildstream/plugin.py | 5 |
1 files 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): |