Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/33276 )

Change subject: python: Use six's with_metaclass instead of it's add_metaclass.
......................................................................

python: Use six's with_metaclass instead of it's add_metaclass.

The decorator creates two versions of a class, adding it to the Params
dict multiple times which generates an annoying warning. Alternatively,
the with_metaclass mechanism sets up an alternative base class which
does not create the extra class and doesn't generate the warning.

It may be the case that this generates extra classes which just don't
lead to a warning? Or in other words, would we then have Params types
with weird, internal names generated by six? Hopefully not, but that may
be preferable to the annoying warnings, especially when running tests
which run gem5 many times.

Change-Id: I9395cde3fc95126c0a0c4db67fc5b0c6bf2dd9ed
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/33276
Reviewed-by: Andreas Sandberg <andreas.sandb...@arm.com>
Maintainer: Andreas Sandberg <andreas.sandb...@arm.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/python/m5/params.py
1 file changed, 7 insertions(+), 14 deletions(-)

Approvals:
  Andreas Sandberg: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/python/m5/params.py b/src/python/m5/params.py
index 2ea614e..5b8fd0c 100644
--- a/src/python/m5/params.py
+++ b/src/python/m5/params.py
@@ -55,7 +55,7 @@
 #####################################################################

 from __future__ import print_function
-from six import add_metaclass
+from six import with_metaclass
 import six
 if six.PY3:
     long = int
@@ -97,8 +97,7 @@

 # Dummy base class to identify types that are legitimate for SimObject
 # parameters.
-@add_metaclass(MetaParamValue)
-class ParamValue(object):
+class ParamValue(with_metaclass(MetaParamValue, object)):
     cmd_line_settable = False

     # Generate the code needed as a prerequisite for declaring a C++
@@ -236,8 +235,7 @@
 # that the value is a vector (list) of the specified type instead of a
 # single value.

-@add_metaclass(MetaParamValue)
-class VectorParamValue(list):
+class VectorParamValue(with_metaclass(MetaParamValue, list)):
     def __setattr__(self, attr, value):
         raise AttributeError("Not allowed to set %s on '%s'" % \
                              (attr, type(self).__name__))
@@ -588,8 +586,7 @@
 # class is subclassed to generate parameter classes with specific
 # bounds.  Initialization of the min and max bounds is done in the
 # metaclass CheckedIntType.__init__.
-@add_metaclass(CheckedIntType)
-class CheckedInt(NumericParamValue):
+class CheckedInt(with_metaclass(CheckedIntType, NumericParamValue)):
     cmd_line_settable = True

     def _check(self):
@@ -1447,8 +1444,7 @@


 # Base class for enum types.
-@add_metaclass(MetaEnum)
-class Enum(ParamValue):
+class Enum(with_metaclass(MetaEnum, ParamValue)):
     vals = []
     cmd_line_settable = True

@@ -1501,7 +1497,6 @@
         return self.value

 # This param will generate a scoped c++ enum and its python bindings.
-@add_metaclass(MetaEnum)
 class ScopedEnum(Enum):
     vals = []
     cmd_line_settable = True
@@ -1789,8 +1784,7 @@
 # make_param_value() above that lets these be assigned where a
 # SimObject is required.
 # only one copy of a particular node
-@add_metaclass(Singleton)
-class NullSimObject(object):
+class NullSimObject(with_metaclass(Singleton, object)):
     _name = 'Null'

     def __call__(cls):
@@ -2157,8 +2151,7 @@
 # 'Fake' ParamDesc for Port references to assign to the _pdesc slot of
 # proxy objects (via set_param_desc()) so that proxy error messages
 # make sense.
-@add_metaclass(Singleton)
-class PortParamDesc(object):
+class PortParamDesc(with_metaclass(Singleton, object)):
     ptype_str = 'Port'
     ptype = Port


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/33276
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I9395cde3fc95126c0a0c4db67fc5b0c6bf2dd9ed
Gerrit-Change-Number: 33276
Gerrit-PatchSet: 3
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-CC: Jason Lowe-Power <power...@gmail.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to