From f8f9463cf7a2ad2ba48886d67b503275a0591b63 Mon Sep 17 00:00:00 2001 From: zhanghao Date: Tue, 26 May 2020 04:18:41 -0400 Subject: [PATCH] Remove usage of six With python3.x, classes can use 'metaclass=' instead of 'six.add_metaclass', 'six.integer_type' can be replaced by 'int', 'six.string_type' and 'six.text_type' are just 'str'. Change-Id: I40a020aa4a8e69a8dd7e800352dc54a9e694d500 --- .pylintrc | 2 +- lower-constraints.txt | 1 - neutron_dynamic_routing/__init__.py | 7 +------ neutron_dynamic_routing/extensions/bgp_dragentscheduler.py | 4 +--- neutron_dynamic_routing/services/bgp/agent/driver/base.py | 5 +---- neutron_dynamic_routing/services/bgp/agent/driver/utils.py | 5 ++--- .../tests/unit/services/bgp/driver/os_ken/test_driver.py | 3 +-- requirements.txt | 1 - 8 files changed, 7 insertions(+), 21 deletions(-) diff --git a/.pylintrc b/.pylintrc index 5115271a..92c21fbc 100644 --- a/.pylintrc +++ b/.pylintrc @@ -123,7 +123,7 @@ deprecated-modules= [TYPECHECK] # List of module names for which member attributes should not be checked -ignored-modules=six.moves,_MovedItems +ignored-modules= [REPORTS] # Tells whether to display a full report or only the messages diff --git a/lower-constraints.txt b/lower-constraints.txt index 4c49eea7..f8aa687f 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -119,7 +119,6 @@ requestsexceptions==1.2.0 rfc3986==0.3.1 Routes==2.3.1 simplejson==3.5.1 -six==1.10.0 snowballstemmer==1.2.1 Sphinx==1.6.5 sphinxcontrib-svg2pdfconverter==0.1.0 # BSD diff --git a/neutron_dynamic_routing/__init__.py b/neutron_dynamic_routing/__init__.py index 208ffbf1..695b3cdc 100644 --- a/neutron_dynamic_routing/__init__.py +++ b/neutron_dynamic_routing/__init__.py @@ -15,10 +15,5 @@ import gettext -import six - -if six.PY2: - gettext.install('neutron', unicode=1) -else: - gettext.install('neutron') +gettext.install('neutron') diff --git a/neutron_dynamic_routing/extensions/bgp_dragentscheduler.py b/neutron_dynamic_routing/extensions/bgp_dragentscheduler.py index 91a71c06..167e53b9 100644 --- a/neutron_dynamic_routing/extensions/bgp_dragentscheduler.py +++ b/neutron_dynamic_routing/extensions/bgp_dragentscheduler.py @@ -24,7 +24,6 @@ from neutron_lib import exceptions as n_exc from neutron_lib.exceptions import agent as agent_exc from neutron_lib.plugins import directory from oslo_log import log as logging -import six import webob from neutron_dynamic_routing._i18n import _, _LE @@ -145,8 +144,7 @@ class Bgp_dragentscheduler(api_extensions.ExtensionDescriptor): return {} -@six.add_metaclass(abc.ABCMeta) -class BgpDrSchedulerPluginBase(object): +class BgpDrSchedulerPluginBase(object, metaclass=abc.ABCMeta): """REST API to operate BGP dynamic routing agent scheduler. All the methods must be executed in admin context. diff --git a/neutron_dynamic_routing/services/bgp/agent/driver/base.py b/neutron_dynamic_routing/services/bgp/agent/driver/base.py index aa4faf5f..5d9e278c 100644 --- a/neutron_dynamic_routing/services/bgp/agent/driver/base.py +++ b/neutron_dynamic_routing/services/bgp/agent/driver/base.py @@ -15,11 +15,8 @@ import abc -import six - -@six.add_metaclass(abc.ABCMeta) -class BgpDriverBase(object): +class BgpDriverBase(object, metaclass=abc.ABCMeta): """Base class for BGP Speaking drivers. Any class which provides BGP functionality should extend this diff --git a/neutron_dynamic_routing/services/bgp/agent/driver/utils.py b/neutron_dynamic_routing/services/bgp/agent/driver/utils.py index 1d5b398a..e379d926 100644 --- a/neutron_dynamic_routing/services/bgp/agent/driver/utils.py +++ b/neutron_dynamic_routing/services/bgp/agent/driver/utils.py @@ -14,7 +14,6 @@ # limitations under the License. import netaddr -import six from neutron_lib import constants as lib_consts @@ -24,7 +23,7 @@ from neutron_dynamic_routing.services.bgp.common import constants as bgp_consts # Parameter validation functions provided are provided by the base. def validate_as_num(param, as_num): - if not isinstance(as_num, six.integer_types): + if not isinstance(as_num, int): raise bgp_driver_exc.InvalidParamType(param=param, param_type='integer') @@ -61,7 +60,7 @@ def validate_ip_addr(ip_addr): def validate_string(param): if param is not None: - if not isinstance(param, six.string_types): + if not isinstance(param, str): raise bgp_driver_exc.InvalidParamType(param=param, param_type='string') diff --git a/neutron_dynamic_routing/tests/unit/services/bgp/driver/os_ken/test_driver.py b/neutron_dynamic_routing/tests/unit/services/bgp/driver/os_ken/test_driver.py index 3d7fbc9f..0965bced 100644 --- a/neutron_dynamic_routing/tests/unit/services/bgp/driver/os_ken/test_driver.py +++ b/neutron_dynamic_routing/tests/unit/services/bgp/driver/os_ken/test_driver.py @@ -20,7 +20,6 @@ from os_ken.services.protocols.bgp import bgpspeaker from os_ken.services.protocols.bgp.rtconf.neighbors import CONNECT_MODE_ACTIVE from oslo_config import cfg from oslo_utils import encodeutils -import six from neutron_dynamic_routing.services.bgp.agent import config as bgp_config from neutron_dynamic_routing.services.bgp.agent.driver import exceptions as bgp_driver_exc # noqa @@ -112,7 +111,7 @@ class TestOsKenBgpDriver(base.BaseTestCase): self.os_ken_bgp_driver.add_bgp_speaker(FAKE_LOCAL_AS1) self.assertEqual(1, self.os_ken_bgp_driver.cache.get_hosted_bgp_speakers_count()) - NEW_FAKE_PEER_PASSWORD = six.text_type(FAKE_PEER_PASSWORD) + NEW_FAKE_PEER_PASSWORD = str(FAKE_PEER_PASSWORD) self.os_ken_bgp_driver.add_bgp_peer( FAKE_LOCAL_AS1, FAKE_PEER_IP, diff --git a/requirements.txt b/requirements.txt index 40fb2b1c..cfc66668 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,6 @@ httplib2>=0.9.1 # MIT netaddr>=0.7.18 # BSD SQLAlchemy>=1.2.0 # MIT alembic>=0.8.10 # MIT -six>=1.10.0 # MIT neutron-lib>=1.26.0 # Apache-2.0 os-ken>=0.3.0 # Apache-2.0 oslo.config>=5.2.0 # Apache-2.0