summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-06-14 10:23:42 +0100
committerBenjamin Schubert <ben.c.schubert@gmail.com>2019-06-25 09:41:55 +0100
commitd4a0acd194de1f7f3fa0990c6db4cd9342ec590d (patch)
tree01619e6afaf9cce695dbc954328207573487891d
parentf61b6ca53313289f6f710a1656d6990fdaf02fdb (diff)
downloadbuildstream-bschubert/node-api-noget-str.tar.gz
_yaml: Never create base 'Node' directlybschubert/node-api-noget-str
We shouldn't have to create normal nodes ever. Let's ensure we don't
-rw-r--r--src/buildstream/_yaml.pyx11
-rw-r--r--src/buildstream/testing/_sourcetests/track.py2
2 files changed, 8 insertions, 5 deletions
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index 24de12526..a166ae757 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -521,13 +521,16 @@ cdef class Representer:
cdef Node _create_node(object value, int file_index, int line, int column):
- if type(value) in [bool, str, type(None), int]:
+ cdef type_value = type(value)
+
+ if type_value in [bool, str, type(None), int]:
return ScalarNode(value, file_index, line, column)
- elif type(value) is dict:
+ elif type_value is dict:
return MappingNode(value, file_index, line, column)
- elif type(value) is list:
+ elif type_value is list:
return SequenceNode(value, file_index, line, column)
- return Node(value, file_index, line, column)
+ raise ValueError(
+ "Node values can only be 'list', 'dict', 'bool', 'str', 'int' or None. Not {}".format(type_value))
# Loads a dictionary from some YAML
diff --git a/src/buildstream/testing/_sourcetests/track.py b/src/buildstream/testing/_sourcetests/track.py
index 08173e79b..58679e9f1 100644
--- a/src/buildstream/testing/_sourcetests/track.py
+++ b/src/buildstream/testing/_sourcetests/track.py
@@ -327,7 +327,7 @@ def test_track_include(cli, tmpdir, datafiles, ref_storage, kind):
# Get the first source from the sources list
new_source = sources_list.mapping_at(0)
assert 'ref' in new_source
- assert ref == new_source.get_scalar('ref').as_str()
+ assert ref == new_source.get_str('ref')
@pytest.mark.datafiles(DATA_DIR)