From e1bbce4c8bc5109f11854967b8f2a674ffe222b5 Mon Sep 17 00:00:00 2001
From: Dominic Kempf <dominic.kempf@iwr.uni-heidelberg.de>
Date: Mon, 29 Aug 2016 10:31:36 +0200
Subject: [PATCH] Use a slightly cleaner approach to fix ConditionDict for
 True/False

---
 python/dune/perftool/generation/cache.py | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/python/dune/perftool/generation/cache.py b/python/dune/perftool/generation/cache.py
index c4255edf..e6032449 100644
--- a/python/dune/perftool/generation/cache.py
+++ b/python/dune/perftool/generation/cache.py
@@ -196,19 +196,14 @@ class _ConditionDict(dict):
             self.tags = tags
 
         def __getitem__(self, i):
-            # If we do not add these special cases the dictionary will return False
-            # when we execute the following code:
-            #
-            # eval ("True", _ConditionDict(v.tags)
-            #
-            # But in this case we want to return True! A normal dictionary would not attempt
-            # to replace "True" if "True" is not a key. The _ConditionDict obviously has no
-            # such concerns ;).
-            if i == "True":
-                return True
-            if i == "False":
-                return False
-            return i in self.tags
+            # We first evaluate the given string with eval. This is necessary
+            # to ensure that 'True' and 'False' are correctly evaluated. Only
+            # if this failed with a NameError, we check for the existence of
+            # of the given string in the tag list.
+            try:
+                return eval(i)
+            except NameError:
+                return i in self.tags
 
 
 def _filter_cache_items(condition):
-- 
GitLab