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

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

and removing pep8 ignore case

Story: 2003430
Task: 27476

Change-Id: If60b8d5662d9a87b217a9b1d48a2c3e9b037884b
Signed-off-by: Sun Austin <austin.sun@intel.com>
This commit is contained in:
Sun Austin 2018-10-15 16:08:04 +08:00
parent d9c7f0bc2f
commit 6753274b28
5 changed files with 10 additions and 12 deletions

View File

@ -24,6 +24,7 @@ Base classes for storage engines
"""
import abc
import six
from sm_api.openstack.common.db import api as db_api
@ -36,11 +37,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

@ -19,6 +19,7 @@
"""Sm common internal object model"""
import collections
import six
from sm_api.common import exception
from sm_api.objects import utils as obj_utils
@ -154,6 +155,7 @@ def check_object_version(server, client):
dict(client=client_minor, server=server_minor))
@six.add_metaclass(Sm_apiObjectMetaclass)
class Sm_apiObject(object):
"""Base class and object factory.
@ -163,7 +165,6 @@ class Sm_apiObject(object):
necessary "get" classmethod routines as well as "save" object methods
as appropriate.
"""
__metaclass__ = Sm_apiObjectMetaclass
# Version of this object (see rules above check_object_version())
version = '1.0'

View File

@ -189,13 +189,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):
"""
@ -549,6 +548,7 @@ def reducer(*tokens):
return decorator
@six.add_metaclass(ParseStateMeta)
class ParseState(object):
"""
Implement the core of parsing the policy language. Uses a greedy
@ -561,8 +561,6 @@ class ParseState(object):
shouldn't be that big a problem.
"""
__metaclass__ = ParseStateMeta
def __init__(self):
"""Initialize the ParseState."""

View File

@ -19,11 +19,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

@ -85,7 +85,6 @@ commands =
# H105: Don't use author tags
# H201: no 'except:'
# H233: Python 3.x incompatible use of print operator
# H236: Python 3.x incompatible __metaclass__, use six.add_metaclass()
# H306: imports not in alphabetical order
# H401: docstring should not start with a space
# H403: multi line docstrings should end on a new line
@ -103,14 +102,13 @@ commands =
# B006 Do not use mutable data structures for argument defaults. (python3)
# B007 Loop control variable 'key' not used within the loop body. If this is intended, start the name with an underscore.
# B008 Do not perform calls in argument defaults. The call is performed only once at function definition time.
# B303 `__metaclass__` does nothing on Python 3. For Python 2 compatibility, use `six.add_metaclass`.
# B305 `.next()` is not a thing on Python 3. Use the `next()` builtin. For Python 2 compatibility, use `six.next()`.
# B306 `BaseException.message` has been deprecated as of Python 2.6 and is removed in Python 3.
ignore= E114,E116,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E228,E231,E241,E251,E265,E271,
E302,E303,E305,E402,E713,E714,E722,E731,E999,
H102,H104,H105,H106,H201,H233,H236,H306,H401,H403,H404,H405,H501,
H102,H104,H105,H106,H201,H233,H306,H401,H403,H404,H405,H501,
F401,F811,F821,F841,
B001,B004,B006,B007,B008,B303,B305,B306
B001,B004,B006,B007,B008,B305,B306
# Enable checks which are off by default
# H106 Dont put vim configuration in source files (off by default). SHOULD BE ENABLED.
# H203 Use assertIs(Not)None to check for None (off by default).