aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase.py
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2018-07-18 09:57:34 -0400
committerJussi Pakkanen <jpakkane@gmail.com>2018-08-14 23:46:42 +0300
commit4f088365e49d28e0d413d42eb024c3ff6cbfee35 (patch)
tree819356912328d5ffd278fbad2f63bc29b2d12e11 /mesonbuild/interpreterbase.py
parent219dec39c09789f2b296e5af00305fe05fa3362b (diff)
downloadmeson-4f088365e49d28e0d413d42eb024c3ff6cbfee35.zip
meson-4f088365e49d28e0d413d42eb024c3ff6cbfee35.tar.gz
meson-4f088365e49d28e0d413d42eb024c3ff6cbfee35.tar.bz2
interpreter: Add support for dict addition
Diffstat (limited to 'mesonbuild/interpreterbase.py')
-rw-r--r--mesonbuild/interpreterbase.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index fd732bc..1c74eeb 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -573,6 +573,8 @@ The result of this is undefined and will become a hard error in a future Meson r
return r
if cur.operation == 'add':
+ if isinstance(l, dict) and isinstance(r, dict):
+ return {**l, **r}
try:
return l + r
except Exception as e:
@@ -651,14 +653,18 @@ The result of this is undefined and will become a hard error in a future Meson r
if not isinstance(addition, int):
raise InvalidArguments('The += operator requires an int on the right hand side if the variable on the left is an int')
new_value = old_variable + addition
- elif not isinstance(old_variable, list):
- raise InvalidArguments('The += operator currently only works with arrays, strings or ints ')
- # Add other data types here.
- else:
+ elif isinstance(old_variable, list):
if isinstance(addition, list):
new_value = old_variable + addition
else:
new_value = old_variable + [addition]
+ elif isinstance(old_variable, dict):
+ if not isinstance(addition, dict):
+ raise InvalidArguments('The += operator requires a dict on the right hand side if the variable on the left is a dict')
+ new_value = {**old_variable, **addition}
+ # Add other data types here.
+ else:
+ raise InvalidArguments('The += operator currently only works with arrays, dicts, strings or ints ')
self.set_variable(varname, new_value)
def evaluate_indexing(self, node):