summaryrefslogtreecommitdiff
path: root/src/buildstream/_yaml.pyx
diff options
context:
space:
mode:
authorbst-marge-bot <marge-bot@buildstream.build>2019-06-07 17:25:11 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2019-06-07 17:25:11 +0000
commit4a8a5a8f17c52522200001159350719c03a65ddd (patch)
tree22d607a3efc72e674f34e26cfecc2d6c13adb46a /src/buildstream/_yaml.pyx
parent20747fc2a275c61d4aa135831e3967aca2081267 (diff)
parentbd3765e3874d82581e86c5a4985ba10e9a1bc60e (diff)
downloadbuildstream-4a8a5a8f17c52522200001159350719c03a65ddd.tar.gz
Merge branch 'bschubert/stricter-node-api' into 'master'
Make the Node api stricter, by only accepting nodes See merge request BuildStream/buildstream!1384
Diffstat (limited to 'src/buildstream/_yaml.pyx')
-rw-r--r--src/buildstream/_yaml.pyx32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index f14b55e51..edad3fbee 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -596,9 +596,9 @@ cpdef object node_get(Node node, object expected_type, str key, list indices=Non
cdef list __trim_list_provenance(list value):
cdef list ret = []
+ cdef Node entry
+
for entry in value:
- if type(entry) is not Node:
- entry = Node(entry, _SYNTHETIC_FILE_INDEX, 0, 0)
if type(entry.value) is list:
ret.append(__trim_list_provenance(entry.value))
elif type(entry.value) is dict:
@@ -624,6 +624,9 @@ cdef list __trim_list_provenance(list value):
cpdef void node_set(Node node, object key, object value, list indices=None) except *:
cdef int idx
+ if type(value) is list:
+ value = __new_node_from_list(value)
+
if indices:
node = <Node> (<dict> node.value)[key]
key = indices.pop()
@@ -693,21 +696,17 @@ def node_extend_list(Node node, str key, Py_ssize_t length, object default):
# tuples in a dictionary loaded from project YAML.
#
# Args:
-# node (dict): The dictionary node
+# node (Node): The dictionary node
#
# Yields:
# (str): The key name
# (anything): The value for the key
#
-def node_items(node):
- if type(node) is not Node:
- node = Node(node, _SYNTHETIC_FILE_INDEX, 0, 0)
-
+def node_items(Node node):
cdef str key
+ cdef Node value
for key, value in node.value.items():
- if type(value) is not Node:
- value = Node(value, _SYNTHETIC_FILE_INDEX, 0, 0)
if type(value.value) is dict:
yield (key, value)
elif type(value.value) is list:
@@ -722,15 +721,13 @@ def node_items(node):
# in a dictionary loaded from project YAML.
#
# Args:
-# node (dict): The dictionary node
+# node (Node): The dictionary node
#
# Yields:
# (str): The key name
#
-cpdef list node_keys(object node):
- if type(node) is Node:
- return list((<Node> node).value.keys())
- return list(node.keys())
+cpdef list node_keys(Node node):
+ return list(node.value.keys())
# node_del()
@@ -1182,11 +1179,10 @@ cpdef Node node_copy(Node source):
# Internal function to help node_copy() but for lists.
cdef Node _list_copy(Node source):
cdef list copy = []
+ cdef Node item
+
for item in source.value:
- if type(item) is Node:
- item_type = type(item.value)
- else:
- item_type = type(item)
+ item_type = type(item.value)
if item_type is dict:
copy.append(node_copy(item))