From: Gabe Black Date: Mon, 24 Aug 2020 03:15:40 +0000 (-0700) Subject: python: Use six's with_metaclass instead of it's add_metaclass. X-Git-Tag: v20.1.0.0~235 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5d420afaa037e41dd0480218db28f08e65279d93;p=gem5.git 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 Maintainer: Andreas Sandberg Tested-by: kokoro --- diff --git a/src/python/m5/params.py b/src/python/m5/params.py index 2ea614e95..5b8fd0cc7 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 @@ class MetaParamValue(type): # 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 @@ class ParamDesc(object): # 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 CheckedIntType(MetaParamValue): # 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 @@ module_init(py::module &m_internal) # 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 @@ class Enum(ParamValue): 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 @@ class MemoryBandwidth(float,ParamValue): # 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 @@ VectorSlavePort = VectorResponsePort # '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