summaryrefslogtreecommitdiff
path: root/src/buildstream/_includes.py
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-06-11 10:48:23 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-07-15 14:14:02 +0000
commitad5aa05826431b1b34c220f20e93bf6e05b292a0 (patch)
treeb73290c2e8fe0a6ef6b3028c5c0b51f94fcc682d /src/buildstream/_includes.py
parent4a56ebe6e589e2aa5d8da3fc2b76f76a19aa03b7 (diff)
downloadbuildstream-ad5aa05826431b1b34c220f20e93bf6e05b292a0.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.
Diffstat (limited to 'src/buildstream/_includes.py')
-rw-r--r--src/buildstream/_includes.py20
1 files changed, 11 insertions, 9 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, '(@)')