Andreas Sandberg has submitted this change and it was merged. (
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]>
Reviewed-on: https://gem5-review.googlesource.com/c/15996
Reviewed-by: Nikos Nikoleris <[email protected]>
---
M src/python/m5/params.py
M src/python/m5/util/smartdict.py
2 files changed, 11 insertions(+), 3 deletions(-)
Approvals:
Nikos Nikoleris: Looks good to me, approved
Andreas Sandberg: Looks good to me, approved
diff --git a/src/python/m5/params.py b/src/python/m5/params.py
index 09aaa5a..b5de6ef 100644
--- a/src/python/m5/params.py
+++ b/src/python/m5/params.py
@@ -829,9 +829,12 @@
# implement truth value testing for Bool parameters so that these
params
# evaluate correctly during the python configuration phase
- def __nonzero__(self):
+ def __bool__(self):
return bool(self.value)
+ # Python 2.7 uses __nonzero__ instead of __bool__
+ __nonzero__ = __bool__
+
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 61e48dd..76b7eb4 100644
--- a/src/python/m5/util/smartdict.py
+++ b/src/python/m5/util/smartdict.py
@@ -55,8 +55,10 @@
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 @@
"""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"""
--
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: 7
Gerrit-Owner: Andreas Sandberg <[email protected]>
Gerrit-Assignee: Ciro Santilli <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Juha Jäykkä <[email protected]>
Gerrit-Reviewer: Nikos Nikoleris <[email protected]>
Gerrit-CC: Ciro Santilli <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev