Andreas Sandberg has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/15996
Change subject: python: Add __bool__ helpers in addition to __nonzero__
......................................................................
python: Add __bool__ helpers in addition to __nonzero__
Python 3 uses __bool__ instead of __nonzero__ when performing a
Boolean comparison.
Change-Id: I85185bbe136ecae67346fa23569e24edd7329222
Signed-off-by: Andreas Sandberg <[email protected]>
---
M src/python/m5/params.py
M src/python/m5/util/smartdict.py
2 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/src/python/m5/params.py b/src/python/m5/params.py
index 9176967..9613994 100644
--- a/src/python/m5/params.py
+++ b/src/python/m5/params.py
@@ -842,6 +842,9 @@
def __nonzero__(self):
return bool(self.value)
+ def __bool__(self):
+ return bool(self.value)
+
def ini_str(self):
if self.value:
return 'true'
diff --git a/src/python/m5/util/smartdict.py
b/src/python/m5/util/smartdict.py
index 59271af..a5ab08a 100644
--- a/src/python/m5/util/smartdict.py
+++ b/src/python/m5/util/smartdict.py
@@ -62,6 +62,8 @@
return toFloat(str(self))
def __nonzero__(self):
return toBool(str(self))
+ def __bool__(self):
+ return toBool(str(self))
def convert(self, other):
t = type(other)
if t == bool:
@@ -114,6 +116,8 @@
zero for boolean truth testing such as in an if statement"""
def __nonzero__(self):
return False
+ def __bool__(self):
+ return False
class SmartDict(attrdict):
"""Dictionary class that holds strings, but intelligently converts
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/15996
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I85185bbe136ecae67346fa23569e24edd7329222
Gerrit-Change-Number: 15996
Gerrit-PatchSet: 1
Gerrit-Owner: Andreas Sandberg <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev