Remove six

Replace the following items with Python 3 style code.

- six.string_types
- six.integer_types
- six.moves
- six.PY2

Implements: blueprint six-removal

Change-Id: I2a0624bd4b455c7e5a0617f1253efa05485dc673
This commit is contained in:
xuanyandong
2020-09-30 09:05:12 +08:00
parent 45dca00dee
commit 16a0486655
6 changed files with 8 additions and 20 deletions

View File

@@ -56,9 +56,6 @@ Here is an example showing how you can write a plugin called ``NewStrategy``:
# filepath: thirdparty/new.py
# import path: thirdparty.new
import abc
import six
from watcher._i18n import _
from watcher.decision_engine.strategy.strategies import base

View File

@@ -19,8 +19,6 @@ Service mechanism provides ability to monitor Watcher services state.
"""
import datetime
import six
from oslo_config import cfg
from oslo_log import log
from oslo_utils import timeutils
@@ -70,7 +68,7 @@ class Service(base.APIBase):
service = objects.Service.get(pecan.request.context, id)
last_heartbeat = (service.last_seen_up or service.updated_at or
service.created_at)
if isinstance(last_heartbeat, six.string_types):
if isinstance(last_heartbeat, str):
# NOTE(russellb) If this service came in over rpc via
# conductor, then the timestamp will be a string and needs to be
# converted back to a datetime.

View File

@@ -15,7 +15,6 @@
from oslo_serialization import jsonutils
from oslo_utils import strutils
import six
import wsme
from wsme import types as wtypes
@@ -132,7 +131,7 @@ class JsonType(wtypes.UserType):
def __str__(self):
# These are the json serializable native types
return ' | '.join(map(str, (wtypes.text, six.integer_types, float,
return ' | '.join(map(str, (wtypes.text, int, float,
BooleanType, list, dict, None)))
@staticmethod

View File

@@ -18,7 +18,6 @@ SQLAlchemy models for watcher service
from oslo_db.sqlalchemy import models
from oslo_serialization import jsonutils
import six.moves.urllib.parse as urlparse
from sqlalchemy import Boolean
from sqlalchemy import Column
from sqlalchemy import DateTime
@@ -33,7 +32,7 @@ from sqlalchemy import String
from sqlalchemy import Text
from sqlalchemy.types import TypeDecorator, TEXT
from sqlalchemy import UniqueConstraint
import urllib.parse as urlparse
from watcher import conf
CONF = conf.CONF

View File

@@ -18,8 +18,6 @@
#
from oslo_log import log
import six
from watcher._i18n import _
from watcher.common import exception
from watcher.decision_engine.model import element
@@ -103,7 +101,7 @@ class HostMaintenance(base.HostMaintenanceBaseStrategy):
def get_instance_state_str(self, instance):
"""Get instance state in string format"""
if isinstance(instance.state, six.string_types):
if isinstance(instance.state, str):
return instance.state
elif isinstance(instance.state, element.InstanceState):
return instance.state.value
@@ -116,7 +114,7 @@ class HostMaintenance(base.HostMaintenanceBaseStrategy):
def get_node_status_str(self, node):
"""Get node status in string format"""
if isinstance(node.status, six.string_types):
if isinstance(node.status, str):
return node.status
elif isinstance(node.status, element.ServiceState):
return node.status.value

View File

@@ -14,14 +14,11 @@
"""Tests for the Pecan API hooks."""
from unittest import mock
from http import client as http_client
from oslo_config import cfg
import oslo_messaging as messaging
from oslo_serialization import jsonutils
import six
from six.moves import http_client
from unittest import mock
from watcher.api.controllers import root
from watcher.api import hooks
from watcher.common import context
@@ -144,7 +141,7 @@ class TestNoExceptionTracebackHook(base.FunctionalTest):
# we don't care about this garbage.
expected_msg = ("Remote error: %s %s"
% (test_exc_type, self.MSG_WITHOUT_TRACE) +
("\n[u'" if six.PY2 else "\n['"))
"\n['")
actual_msg = jsonutils.loads(
response.json['error_message'])['faultstring']
self.assertEqual(expected_msg, actual_msg)