From 6a4a4deb684c5d0496bc49508bc206b3dd1d1c4b Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Thu, 30 Nov 2023 02:24:36 +0100 Subject: [PATCH] remove remaining six usage --- .pylintrc | 2 +- pyocd/commands/execution_context.py | 3 +-- pyocd/probe/jlink_probe.py | 3 +-- pyocd/probe/pydapaccess/interface/hidapi_backend.py | 3 +-- setup.cfg | 1 - test/basic_test.py | 2 -- test/blank_test.py | 2 -- test/commands_test.py | 2 -- test/concurrency_test.py | 2 -- test/connect_test.py | 2 -- test/cortex_test.py | 2 -- test/debug_context_test.py | 2 -- test/flash_loader_test.py | 2 -- test/flash_test.py | 2 -- test/gdb_test.py | 1 - test/gdb_test_script.py | 1 - test/json_lists_test.py | 2 -- test/parallel_test.py | 2 -- test/probeserver_test.py | 1 - test/speed_test.py | 1 - test/test_util.py | 8 +++----- test/unit/test_cmdline.py | 3 +-- test/unit/test_conversion.py | 7 +++---- test/unit/test_notification.py | 1 - test/unit/test_options_manager.py | 1 - test/unit/test_sdc600.py | 1 - test/unit/test_semihosting.py | 13 ++++++------- test/unit/test_sequencer.py | 7 +++---- test/user_script_test.py | 1 - 29 files changed, 20 insertions(+), 60 deletions(-) diff --git a/.pylintrc b/.pylintrc index 4d4d92247..1e5510914 100644 --- a/.pylintrc +++ b/.pylintrc @@ -319,7 +319,7 @@ init-import=no # List of qualified module names which can have objects that can redefine # builtins. -redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io +redefining-builtins-modules=builtins,io [FORMAT] diff --git a/pyocd/commands/execution_context.py b/pyocd/commands/execution_context.py index adc0695a1..11a54ef19 100755 --- a/pyocd/commands/execution_context.py +++ b/pyocd/commands/execution_context.py @@ -21,7 +21,6 @@ import sys from typing import (Any, Callable, cast, Dict, IO, Iterator, List, NamedTuple, Optional, Sequence, TYPE_CHECKING) -import six import pprint import subprocess from shutil import get_terminal_size @@ -493,6 +492,6 @@ def handle_system(self, invocation: CommandInvocation) -> None: """@brief Evaluate a system call command.""" try: output = subprocess.check_output(invocation.cmd, stderr=subprocess.STDOUT, shell=True) - self.write(six.ensure_str(output), end='') + self.write(str(output), end='') except subprocess.CalledProcessError as err: raise exceptions.CommandError(str(err)) from err diff --git a/pyocd/probe/jlink_probe.py b/pyocd/probe/jlink_probe.py index b844ddf64..9947346e7 100644 --- a/pyocd/probe/jlink_probe.py +++ b/pyocd/probe/jlink_probe.py @@ -16,7 +16,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import six import logging from time import sleep import pylink @@ -128,7 +127,7 @@ def __init__(self, serial_number): self._protocol = None self._default_protocol = None self._is_open = False - self._product_name = six.ensure_str(info.acProduct) + self._product_name = str(info.acProduct) self._memory_interfaces = {} @property diff --git a/pyocd/probe/pydapaccess/interface/hidapi_backend.py b/pyocd/probe/pydapaccess/interface/hidapi_backend.py index 780fab576..e28d51322 100644 --- a/pyocd/probe/pydapaccess/interface/hidapi_backend.py +++ b/pyocd/probe/pydapaccess/interface/hidapi_backend.py @@ -18,7 +18,6 @@ import logging import platform -import six import threading import queue from typing import Optional @@ -63,7 +62,7 @@ def __init__(self, dev, info: dict): self.vendor_name = info['manufacturer_string'] or f"{self.vid:#06x}" self.product_name = info['product_string'] or f"{self.pid:#06x}" self.serial_number = info['serial_number'] \ - or generate_device_unique_id(self.vid, self.pid, six.ensure_str(info['path'])) + or generate_device_unique_id(self.vid, self.pid, str(info['path'])) self.device_info = info self.device = dev self.closed = True diff --git a/setup.cfg b/setup.cfg index d27543a50..23be9100f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,7 +66,6 @@ install_requires = pylink-square>=1.0,<2.0 pyusb>=1.2.1,<2.0 pyyaml>=6.0,<7.0 - six>=1.15.0,<2.0 typing-extensions>=4.0,<5.0 [options.extras_require] diff --git a/test/basic_test.py b/test/basic_test.py index dff819d21..8b2f32db9 100644 --- a/test/basic_test.py +++ b/test/basic_test.py @@ -13,8 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import argparse import os import sys diff --git a/test/blank_test.py b/test/blank_test.py index 105f122b9..3418331a9 100644 --- a/test/blank_test.py +++ b/test/blank_test.py @@ -14,8 +14,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import os import sys from time import sleep diff --git a/test/commands_test.py b/test/commands_test.py index 47a162781..de3270530 100644 --- a/test/commands_test.py +++ b/test/commands_test.py @@ -13,8 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import argparse import sys import traceback diff --git a/test/concurrency_test.py b/test/concurrency_test.py index 6c273303b..e63662523 100644 --- a/test/concurrency_test.py +++ b/test/concurrency_test.py @@ -13,8 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import argparse import os import sys diff --git a/test/connect_test.py b/test/connect_test.py index 78c7927a7..7c8a882ba 100644 --- a/test/connect_test.py +++ b/test/connect_test.py @@ -13,8 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import os import sys import traceback diff --git a/test/cortex_test.py b/test/cortex_test.py index d90f7d661..b3fcf7409 100644 --- a/test/cortex_test.py +++ b/test/cortex_test.py @@ -13,8 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import argparse import os import sys diff --git a/test/debug_context_test.py b/test/debug_context_test.py index 80bbce99c..3cffc2234 100644 --- a/test/debug_context_test.py +++ b/test/debug_context_test.py @@ -14,8 +14,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import argparse import os import sys diff --git a/test/flash_loader_test.py b/test/flash_loader_test.py index efd5c0d62..69c175c39 100644 --- a/test/flash_loader_test.py +++ b/test/flash_loader_test.py @@ -13,8 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import argparse import os import sys diff --git a/test/flash_test.py b/test/flash_test.py index b52fbe2f3..c46447472 100644 --- a/test/flash_test.py +++ b/test/flash_test.py @@ -13,8 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import argparse import os import sys diff --git a/test/gdb_test.py b/test/gdb_test.py index 19357e736..a8aec6fcd 100644 --- a/test/gdb_test.py +++ b/test/gdb_test.py @@ -14,7 +14,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function # Note # To run this script GNU Tools ARM Embedded must be installed, diff --git a/test/gdb_test_script.py b/test/gdb_test_script.py index 5aa16621f..28a951075 100644 --- a/test/gdb_test_script.py +++ b/test/gdb_test_script.py @@ -14,7 +14,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function # Notes about this script # 1. This script runs inside arm-none-eabi-gdb-py diff --git a/test/json_lists_test.py b/test/json_lists_test.py index d72ea940f..e89045e1a 100644 --- a/test/json_lists_test.py +++ b/test/json_lists_test.py @@ -13,8 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import argparse, os, sys from time import sleep, time from random import randrange diff --git a/test/parallel_test.py b/test/parallel_test.py index 2a61a00ed..f9b687ecf 100644 --- a/test/parallel_test.py +++ b/test/parallel_test.py @@ -13,8 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import threading import multiprocessing diff --git a/test/probeserver_test.py b/test/probeserver_test.py index fce0edce4..4a149885c 100644 --- a/test/probeserver_test.py +++ b/test/probeserver_test.py @@ -13,7 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function # Note # To run this script GNU Tools ARM Embedded must be installed, diff --git a/test/speed_test.py b/test/speed_test.py index cf227597c..8bb527ffd 100644 --- a/test/speed_test.py +++ b/test/speed_test.py @@ -14,7 +14,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function import os import sys diff --git a/test/test_util.py b/test/test_util.py index 954f82009..b41bc2f5b 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -14,14 +14,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function import logging import os import sys import traceback from xml.etree import ElementTree -import six import subprocess import tempfile import threading @@ -195,7 +193,7 @@ def __init__(self, iostream, level=logging.NOTSET): def emit(self, record): try: message = self.format(record) - self.stream.write(six.u(message + "\n")) + self.stream.write(message + "\n") except Exception: self.handleError(record) @@ -244,10 +242,10 @@ def get_test_case(self): def filter_output(self, output): """@brief Hex-encode null byte and control characters.""" - result = six.text_type() + result = str() for c in output: if (c not in ('\n', '\r', '\t')) and (0 <= ord(c) <= 31): - result += u"\\x{:02x}".format(ord(c)) + result += "\\x{:02x}".format(ord(c)) else: result += c return result diff --git a/test/unit/test_cmdline.py b/test/unit/test_cmdline.py index 3c547df4d..868f41b7a 100644 --- a/test/unit/test_cmdline.py +++ b/test/unit/test_cmdline.py @@ -16,7 +16,6 @@ # limitations under the License. import pytest -import six from pyocd.utility.cmdline import ( split_command_line, @@ -89,7 +88,7 @@ def test_vc_str(self, vc, msk): assert convert_vector_catch(vc) == msk @pytest.mark.parametrize(("vc", "msk"), - [(six.b(x), y) for x,y in VECTOR_CATCH_CHAR_MAP.items()]) + [(x.encode('latin1'), y) for x,y in VECTOR_CATCH_CHAR_MAP.items()]) def test_vc_b(self, vc, msk): assert convert_vector_catch(vc) == msk diff --git a/test/unit/test_conversion.py b/test/unit/test_conversion.py index c683b5fd9..500c27d75 100644 --- a/test/unit/test_conversion.py +++ b/test/unit/test_conversion.py @@ -16,7 +16,6 @@ # limitations under the License. import pytest -import six from pyocd.utility.conversion import ( byte_list_to_nbit_le_list, @@ -245,7 +244,7 @@ def test_align_down(self, args, result): class TestGdbEscape(object): # Verify all chars that shouldn't be escaped pass through unmodified. @pytest.mark.parametrize("data", - [six.int2byte(x) for x in range(256) if (x not in ESCAPEES)]) + [bytes((x,)) for x in range(256) if (x not in ESCAPEES)]) def test_escape_passthrough(self, data): assert escape(data) == data @@ -263,9 +262,9 @@ def test_escape_2(self): # Verify all chars that shouldn't be escaped pass through unmodified. @pytest.mark.parametrize("data", - [six.int2byte(x) for x in range(256) if (x not in ESCAPEES)]) + [bytes((x,)) for x in range(256) if (x not in ESCAPEES)]) def test_unescape_passthrough(self, data): - assert unescape(data) == [six.byte2int(data)] + assert unescape(data) == [data[0]] @pytest.mark.parametrize(("expected", "data"), [ (0x23, b'}\x03'), diff --git a/test/unit/test_notification.py b/test/unit/test_notification.py index b6d8877c4..f0635069f 100644 --- a/test/unit/test_notification.py +++ b/test/unit/test_notification.py @@ -15,7 +15,6 @@ # limitations under the License. import pytest -import six from enum import Enum from pyocd.utility.notification import (Notification, Notifier) diff --git a/test/unit/test_options_manager.py b/test/unit/test_options_manager.py index 518d2a96d..d8659ffaf 100644 --- a/test/unit/test_options_manager.py +++ b/test/unit/test_options_manager.py @@ -15,7 +15,6 @@ # limitations under the License. import pytest -import six from pyocd.core.options_manager import OptionsManager from pyocd.core.options import OPTIONS_INFO diff --git a/test/unit/test_sdc600.py b/test/unit/test_sdc600.py index 91ebb294e..70d52f1c1 100644 --- a/test/unit/test_sdc600.py +++ b/test/unit/test_sdc600.py @@ -16,7 +16,6 @@ # limitations under the License. import pytest -import six from unittest import mock from .test_rom_table import (MockCoreSightComponent, MockCoreSight, MockCSSOC600Components) diff --git a/test/unit/test_semihosting.py b/test/unit/test_semihosting.py index 981b133ba..6bc0d5d32 100644 --- a/test/unit/test_semihosting.py +++ b/test/unit/test_semihosting.py @@ -21,7 +21,6 @@ import os import logging # import telnetlib -import six from pyocd.core.helpers import ConnectHelper from pyocd.core.target import Target @@ -128,7 +127,7 @@ def read(self, fd, ptr, length): d = self._in_data[fd][:length] self._in_data[fd] = self._in_data[fd][length:] assert self.agent - self.agent.context.write_memory_block8(ptr, bytearray(six.ensure_binary(d))) + self.agent.context.write_memory_block8(ptr, bytearray(bytes(d))) return length - len(d) def readc(self): @@ -170,7 +169,7 @@ def do_open(self, filename, mode): argsptr = self.setup_semihost_request(semihost.SemihostingRequests.SYS_OPEN) # Write filename - filename = bytearray(six.ensure_binary(filename) + b'\x00') + filename = bytearray(bytes(filename) + b'\x00') self.ctx.write_memory_block8(argsptr + 12, filename) self.ctx.write32(argsptr, argsptr + 12) # null terminated filename @@ -197,7 +196,7 @@ def do_write(self, fd, data): argsptr = self.setup_semihost_request(semihost.SemihostingRequests.SYS_WRITE) # Write data - data = six.ensure_binary(data) + data = bytes(data) self.ctx.write_memory_block8(argsptr + 12, data) self.ctx.write32(argsptr, fd) # fd @@ -388,7 +387,7 @@ def test_file_write_read(self, semihost_builder, delete_testfile, mode, writeDat assert result == 0 result = semihost_builder.do_flen(fd) - assert result == len(six.ensure_binary(writeData)) + assert result == len(bytes(writeData)) if pos != -1: result = semihost_builder.do_seek(fd, pos) @@ -396,7 +395,7 @@ def test_file_write_read(self, semihost_builder, delete_testfile, mode, writeDat result, data = semihost_builder.do_read(fd, readLen) assert result == readResult - assert data == six.ensure_binary(writeData[pos:pos + readLen]) + assert data == bytes(writeData[pos:pos + readLen]) result = semihost_builder.do_close(fd) assert result == 0 @@ -676,7 +675,7 @@ class TestSemihostIOHandlerBase: ]) def test_std_open(self, ctx, ramrgn, ioh, filename, mode, expectedFd): handler, agent = ioh - ctx.write_memory_block8(ramrgn.start, bytearray(six.ensure_binary(filename) + b'\x00')) + ctx.write_memory_block8(ramrgn.start, bytearray(bytes(filename) + b'\x00')) assert handler._std_open(ramrgn.start, len(filename), mode) == (expectedFd, filename) @pytest.mark.parametrize(("op", "args"), [ diff --git a/test/unit/test_sequencer.py b/test/unit/test_sequencer.py index e612561e4..925793021 100644 --- a/test/unit/test_sequencer.py +++ b/test/unit/test_sequencer.py @@ -16,7 +16,6 @@ # limitations under the License. import pytest -import six from pyocd.utility.sequencer import CallSequence @@ -127,10 +126,10 @@ def task_b(): assert cs.count == 2 it = iter(cs) print("it=",repr(it),dir(it)) - assert six.next(it) == ('a', task_a) - assert six.next(it) == ('b', task_b) + assert next(it) == ('a', task_a) + assert next(it) == ('b', task_b) with pytest.raises(StopIteration): - six.next(it) + next(it) def test_get(self): results = [] diff --git a/test/user_script_test.py b/test/user_script_test.py index 747429ddf..6c1101bff 100644 --- a/test/user_script_test.py +++ b/test/user_script_test.py @@ -13,7 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function import argparse import os