diff options
Diffstat (limited to 'src/python/m5/util')
-rw-r--r-- | src/python/m5/util/smartdict.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/python/m5/util/smartdict.py b/src/python/m5/util/smartdict.py index 61e48ddba..76b7eb4f8 100644 --- a/src/python/m5/util/smartdict.py +++ b/src/python/m5/util/smartdict.py @@ -55,8 +55,10 @@ class Variable(str): return toLong(str(self)) def __float__(self): return toFloat(str(self)) - def __nonzero__(self): + def __bool__(self): return toBool(str(self)) + # Python 2.7 uses __nonzero__ instead of __bool__ + __nonzero__ = __bool__ def convert(self, other): t = type(other) if t == bool: @@ -107,9 +109,12 @@ class UndefinedVariable(object): """Placeholder class to represent undefined variables. Will generally cause an exception whenever it is used, but evaluates to zero for boolean truth testing such as in an if statement""" - def __nonzero__(self): + def __bool__(self): return False + # Python 2.7 uses __nonzero__ instead of __bool__ + __nonzero__ = __bool__ + class SmartDict(attrdict): """Dictionary class that holds strings, but intelligently converts those strings to other types depending on their usage""" |