python: Make meta class declarations Python 3 safe
Python 2.x and Python 3 use different meta class syntax. Fix this by implementing meta classes using the add_metaclass decorator in the six Python library. Due to the way meta classes are implemented in six, MetaParamValue.__new__ seems to be called twice for some classes. This triggers an assertion which when param that checks that Param types have only been registered once. I have turned this assertion into a warning. The assertion was triggered in params.CheckedInt and params.Enum. It seems like the cause of the issue is that these classes have their own meta classes (CheckedIntType and MetaEnum) that inherit from MetaParamValue and a base class (ParamValue) that also inherits from MetaParamValue. Change-Id: I5dea08bf0558cfca57897a124cb131c78114e59e Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/26083 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Maintainer: Jason Lowe-Power <jason@lowepower.com>
This commit is contained in:
committed by
Giacomo Travaglini
parent
ee9a360c60
commit
5d70afd3a9
@@ -25,6 +25,7 @@
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
from __future__ import print_function
|
||||
from six import add_metaclass
|
||||
|
||||
try:
|
||||
import builtins
|
||||
@@ -112,9 +113,8 @@ class code_formatter_meta(type):
|
||||
}
|
||||
cls.pattern = re.compile(pat, re.VERBOSE | re.DOTALL | re.MULTILINE)
|
||||
|
||||
@add_metaclass(code_formatter_meta)
|
||||
class code_formatter(object):
|
||||
__metaclass__ = code_formatter_meta
|
||||
|
||||
delim = r'$'
|
||||
ident = r'[_A-z]\w*'
|
||||
pos = r'[0-9]+'
|
||||
|
||||
Reference in New Issue
Block a user