Implement merge_over method for CompItem class
Required for overwriting escaped strings with either another escaped
string or a scalar. As CompItem objects render as strings the merge_over
method is the same as for ScalarItem objects
diff --git a/reclass/values/compitem.py b/reclass/values/compitem.py
index 765b323..c6e8863 100644
--- a/reclass/values/compitem.py
+++ b/reclass/values/compitem.py
@@ -39,6 +39,21 @@
def get_references(self):
return self._refs
+ def merge_over(self, item):
+ if item.type == Item.SCALAR or item.type == Item.COMPOSITE:
+ return self
+ elif item.type == Item.LIST:
+ if self._settings.allow_scalar_over_list or (self._settings.allow_none_override and self._value in [None, 'none', 'None']):
+ return self
+ else:
+ raise TypeError('allow scalar over list = False: cannot merge %s over %s' % (repr(self), repr(item)))
+ elif item.type == Item.DICTIONARY:
+ if self._settings.allow_scalar_over_dict or (self._settings.allow_none_override and self._value in [None, 'none', 'None']):
+ return self
+ else:
+ raise TypeError('allow scalar over dict = False: cannot merge %s over %s' % (repr(self), repr(item)))
+ raise TypeError('Cannot merge %s over %s' % (repr(self), repr(item)))
+
def render(self, context, inventory):
# Preserve type if only one item
if len(self._items) == 1:
diff --git a/reclass/values/scaitem.py b/reclass/values/scaitem.py
index 9de5681..f4265b5 100644
--- a/reclass/values/scaitem.py
+++ b/reclass/values/scaitem.py
@@ -18,7 +18,7 @@
return self._value
def merge_over(self, item):
- if item.type == Item.SCALAR:
+ if item.type == Item.SCALAR or item.type == Item.COMPOSITE:
return self
elif item.type == Item.LIST:
if self._settings.allow_scalar_over_list or (self._settings.allow_none_override and self._value is None):