Fix: "metaclass" issues for Python 2/3 compatible code.

remove "__metaclass__ = abc.ABCMeta"
and adding decorator "@six.add_metaclass(abc.ABCMeta)" on class

Story: 2003433
Task: 27651

Change-Id: Ib9e3626ffafcacf8085c65919238444860021d3c
Signed-off-by: zhangyangyang <zhangyangyang@unionpay.com>
This commit is contained in:
zhangyangyang 2018-10-25 14:06:30 +08:00
parent 3a29c1170d
commit 5af6e7847a
5 changed files with 10 additions and 9 deletions

View File

@ -25,6 +25,7 @@ Base classes for storage engines
"""
import abc
import six
from oslo_config import cfg
from oslo_db import api as db_api
@ -46,11 +47,10 @@ def get_instance():
return IMPL
@six.add_metaclass(abc.ABCMeta)
class Connection(object):
"""Base class for storage system connections."""
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def __init__(self):
"""Constructor."""

View File

@ -20,6 +20,7 @@
import collections
import copy
import six
from sysinv.common import exception
from sysinv.objects import utils as obj_utils
@ -156,6 +157,7 @@ def check_object_version(server, client):
dict(client=client_minor, server=server_minor))
@six.add_metaclass(SysinvObjectMetaclass)
class SysinvObject(object):
"""Base class and object factory.
@ -165,7 +167,6 @@ class SysinvObject(object):
necessary "get" classmethod routines as well as "save" object methods
as appropriate.
"""
__metaclass__ = SysinvObjectMetaclass
# Version of this object (see rules above check_object_version())
version = '1.0'

View File

@ -185,13 +185,12 @@ def check(rule, target, creds, exc=None, *args, **kwargs):
return result
@six.add_metaclass(abc.ABCMeta)
class BaseCheck(object):
"""
Abstract base class for Check classes.
"""
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def __str__(self):
"""
@ -545,6 +544,7 @@ def reducer(*tokens):
return decorator
@six.add_metaclass(ParseStateMeta)
class ParseState(object):
"""
Implement the core of parsing the policy language. Uses a greedy
@ -557,8 +557,6 @@ class ParseState(object):
shouldn't be that big a problem.
"""
__metaclass__ = ParseStateMeta
def __init__(self):
"""Initialize the ParseState."""

View File

@ -15,11 +15,12 @@
"""Provides the definition of an RPC serialization handler"""
import abc
import six
@six.add_metaclass(abc.ABCMeta)
class Serializer(object):
"""Generic (de-)serialization definition base class"""
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def serialize_entity(self, context, entity):

View File

@ -17,6 +17,7 @@ import datetime
import gettext
import iso8601
import netaddr
import six
gettext.install('sysinv')
@ -87,8 +88,8 @@ class MyObj2(object):
class TestMetaclass(test_base.TestCase):
def test_obj_tracking(self):
@six.add_metaclass(base.SysinvObjectMetaclass)
class NewBaseClass(object):
__metaclass__ = base.SysinvObjectMetaclass
fields = {}
@classmethod