From 7d03255181d62fb5cc1975261ce0586f4e03ffdb Mon Sep 17 00:00:00 2001 From: Brian Haley Date: Mon, 20 Jan 2020 15:36:17 -0500 Subject: [PATCH] Remove all usage of six library Convert all code to not require six library and instead use python 3.x logic. Change-Id: I32d9f261a219ab4dc95a697d9ab1ff5d9298aee8 --- octavia_lib/api/drivers/data_models.py | 4 --- octavia_lib/hacking/checks.py | 33 +------------------ .../tests/unit/api/drivers/test_driver_lib.py | 2 +- octavia_lib/tests/unit/hacking/test_checks.py | 19 +---------- requirements.txt | 1 - 5 files changed, 3 insertions(+), 56 deletions(-) diff --git a/octavia_lib/api/drivers/data_models.py b/octavia_lib/api/drivers/data_models.py index b04403b..1fdb8e9 100644 --- a/octavia_lib/api/drivers/data_models.py +++ b/octavia_lib/api/drivers/data_models.py @@ -15,8 +15,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six - class BaseDataModel(object): def to_dict(self, calling_classes=None, recurse=False, @@ -52,8 +50,6 @@ class BaseDataModel(object): calling_classes=calling_classes + [type(self)]) else: ret[attr] = None - elif six.PY2 and isinstance(value, six.text_type): - ret[attr.encode('utf8')] = value.encode('utf8') elif isinstance(value, UnsetType): if render_unsets: ret[attr] = None diff --git a/octavia_lib/hacking/checks.py b/octavia_lib/hacking/checks.py index 506972a..26f9214 100644 --- a/octavia_lib/hacking/checks.py +++ b/octavia_lib/hacking/checks.py @@ -57,13 +57,10 @@ assert_not_equal_end_with_none_re = re.compile( r"(.)*assertNotEqual\(.+, None\)") assert_not_equal_start_with_none_re = re.compile( r"(.)*assertNotEqual\(None, .+\)") -assert_no_xrange_re = re.compile( - r"\s*xrange\s*\(") revert_must_have_kwargs_re = re.compile( r'[ ]*def revert\(.+,[ ](?!\*\*kwargs)\w+\):') untranslated_exception_re = re.compile(r"raise (?:\w*)\((.*)\)") no_basestring_re = re.compile(r"\bbasestring\b") -no_iteritems_re = re.compile(r".*\.iteritems\(\)") no_eventlet_re = re.compile(r'(import|from)\s+[(]?eventlet') no_line_continuation_backslash_re = re.compile(r'.*(\\)\n') no_logging_re = re.compile(r'(import|from)\s+[(]?logging') @@ -182,15 +179,6 @@ def no_log_warn(logical_line): yield(0, "O339:Use LOG.warning() rather than LOG.warn()") -def no_xrange(logical_line): - """Disallow 'xrange()' - - O340 - """ - if assert_no_xrange_re.match(logical_line): - yield(0, "O340: Do not use xrange().") - - def no_translate_logs(logical_line, filename): """O341 - Don't translate logs. @@ -247,24 +235,7 @@ def check_no_basestring(logical_line): """ if no_basestring_re.search(logical_line): msg = ("O343: basestring is not Python3-compatible, use " - "six.string_types instead.") - yield(0, msg) - - -def check_python3_no_iteritems(logical_line): - """O344 - Use dict.items() instead of dict.iteritems(). - - :param logical_line: The logical line to check. - :returns: None if the logical line passes the check, otherwise a tuple - is yielded that contains the offending index in logical line - and a message describe the check validation failure. - """ - if no_iteritems_re.search(logical_line): - msg = ("O344: Use dict.items() instead of dict.iteritems() to be " - "compatible with both Python 2 and Python 3. In Python 2, " - "dict.items() may be inefficient for very large dictionaries. " - "If you can prove that you need the optimization of an " - "iterator for Python 2, then you can use six.iteritems(dict).") + "str instead.") yield(0, msg) @@ -338,10 +309,8 @@ def factory(register): register(no_mutable_default_args) register(assert_equal_in) register(no_log_warn) - register(no_xrange) register(check_raised_localized_exceptions) register(check_no_basestring) - register(check_python3_no_iteritems) register(check_no_eventlet_imports) register(check_line_continuation_no_backslash) register(check_no_logging_imports) diff --git a/octavia_lib/tests/unit/api/drivers/test_driver_lib.py b/octavia_lib/tests/unit/api/drivers/test_driver_lib.py index 0e3ecd4..fbaad3a 100644 --- a/octavia_lib/tests/unit/api/drivers/test_driver_lib.py +++ b/octavia_lib/tests/unit/api/drivers/test_driver_lib.py @@ -43,7 +43,7 @@ class TestDriverLib(base.TestCase): self.driver_lib._check_for_socket_ready, 'bogus') - @mock.patch('six.moves.builtins.memoryview') + @mock.patch('builtins.memoryview') def test_recv(self, mock_memoryview): mock_socket = mock.MagicMock() mock_socket.recv.side_effect = [b'1', b'\n', b'2', b'\n', b'3', b'\n'] diff --git a/octavia_lib/tests/unit/hacking/test_checks.py b/octavia_lib/tests/unit/hacking/test_checks.py index 663e7b7..4c2b147 100644 --- a/octavia_lib/tests/unit/hacking/test_checks.py +++ b/octavia_lib/tests/unit/hacking/test_checks.py @@ -167,13 +167,6 @@ class HackingTestCase(base.BaseTestCase): self.assertEqual(0, len(list(checks.no_log_warn( "LOG.warning()")))) - def test_no_xrange(self): - self.assertEqual(1, len(list(checks.no_xrange( - "xrange(45)")))) - - self.assertEqual(0, len(list(checks.no_xrange( - "range(45)")))) - def test_no_log_translations(self): for log in checks._all_log_levels: for hint in checks._all_hints: @@ -210,17 +203,7 @@ class HackingTestCase(base.BaseTestCase): "isinstance('foo', basestring)")))) self.assertEqual(0, len(list(checks.check_no_basestring( - "isinstance('foo', six.string_types)")))) - - def test_dict_iteritems(self): - self.assertEqual(1, len(list(checks.check_python3_no_iteritems( - "obj.iteritems()")))) - - self.assertEqual(0, len(list(checks.check_python3_no_iteritems( - "six.iteritems(obj)")))) - - self.assertEqual(0, len(list(checks.check_python3_no_iteritems( - "obj.items()")))) + "isinstance('foo', str)")))) def test_check_no_eventlet_imports(self): f = checks.check_no_eventlet_imports diff --git a/requirements.txt b/requirements.txt index 74375a9..2575953 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,4 @@ oslo.i18n>=3.15.3 # Apache-2.0 oslo.serialization>=2.28.1 # Apache-2.0 pbr!=2.1.0,>=2.0.0 # Apache-2.0 -six>=1.10.0 # MIT tenacity>=5.0.2 # Apache-2.0