summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-06-11 10:48:23 +0100
committerBenjamin Schubert <ben.c.schubert@gmail.com>2019-07-09 16:55:52 +0100
commitecf869042477b2bbd9e8839f6285d43c837d2f8f (patch)
tree219cfecbe611baaafd8cc89a6674a06437aca694
parentf17c0571bb1af2cceba07a247c3fe5d6be7b2f48 (diff)
downloadbuildstream-ecf869042477b2bbd9e8839f6285d43c837d2f8f.tar.gz
_yaml: Remove use of expected_type=None in 'node_get()'
In a strongly typed API with Node, having a 'None' as expected type is hard to make nice. Moreover, this is rarely used in the codebase. Thus, adapting the call sites to not use 'None' as an expected type.
-rw-r--r--src/buildstream/_includes.py20
-rw-r--r--tests/frontend/cross_junction_workspace.py3
-rw-r--r--tests/frontend/workspace.py1
3 files changed, 11 insertions, 13 deletions
diff --git a/src/buildstream/_includes.py b/src/buildstream/_includes.py
index 8f507b566..133cf50d0 100644
--- a/src/buildstream/_includes.py
+++ b/src/buildstream/_includes.py
@@ -35,16 +35,18 @@ class Includes:
if current_loader is None:
current_loader = self._loader
- includes = _yaml.node_get(node, None, '(@)', default_value=None)
- if isinstance(includes, str):
- includes = [includes]
+ try:
+ includes = node.get_str('(@)', default=None)
+ if includes is not None:
+ includes = [includes]
+ except LoadError:
+ try:
+ includes = _yaml.node_get(node, list, '(@)')
+ except LoadError:
+ provenance = _yaml.node_get_provenance(node, key='(@)')
+ raise LoadError(LoadErrorReason.INVALID_DATA,
+ "{}: {} must either be list or str".format(provenance, _yaml.node_sanitize(node)))
- if not isinstance(includes, list) and includes is not None:
- provenance = _yaml.node_get_provenance(node, key='(@)')
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: {} must either be list or str".format(provenance, includes))
-
- include_provenance = None
if includes:
include_provenance = _yaml.node_get_provenance(node, key='(@)')
_yaml.node_del(node, '(@)')
diff --git a/tests/frontend/cross_junction_workspace.py b/tests/frontend/cross_junction_workspace.py
index 14039186c..974aba4bd 100644
--- a/tests/frontend/cross_junction_workspace.py
+++ b/tests/frontend/cross_junction_workspace.py
@@ -75,7 +75,6 @@ def test_list_cross_junction(cli, tmpdir):
result.assert_success()
loaded = _yaml.load_data(result.output)
- assert isinstance(_yaml.node_get(loaded, None, 'workspaces'), list)
workspaces = _yaml.node_get(loaded, list, 'workspaces')
assert len(workspaces) == 1
assert 'element' in workspaces[0]
@@ -97,7 +96,6 @@ def test_close_cross_junction(cli, tmpdir):
result.assert_success()
loaded = _yaml.load_data(result.output)
- assert isinstance(_yaml.node_get(loaded, None, 'workspaces'), list)
workspaces = _yaml.node_get(loaded, list, 'workspaces')
assert not workspaces
@@ -116,7 +114,6 @@ def test_close_all_cross_junction(cli, tmpdir):
result.assert_success()
loaded = _yaml.load_data(result.output)
- assert isinstance(_yaml.node_get(loaded, None, 'workspaces'), list)
workspaces = _yaml.node_get(loaded, list, 'workspaces')
assert not workspaces
diff --git a/tests/frontend/workspace.py b/tests/frontend/workspace.py
index 7ca06bdd4..339f0d496 100644
--- a/tests/frontend/workspace.py
+++ b/tests/frontend/workspace.py
@@ -608,7 +608,6 @@ def test_list(cli, tmpdir, datafiles):
result.assert_success()
loaded = _yaml.load_data(result.output)
- assert isinstance(_yaml.node_get(loaded, None, 'workspaces'), list)
workspaces = _yaml.node_get(loaded, list, 'workspaces')
assert len(workspaces) == 1