From d4bb580ab1627612e173c63799a27f6ac5cdb332 Mon Sep 17 00:00:00 2001 From: Kashiko Koibumi Date: Sun, 26 May 2024 11:17:30 +0900 Subject: [PATCH] fix importing collections for Python3 --- src/fallback/umsgpack/umsgpack.py | 7 ++++--- src/multiqueue.py | 2 +- src/network/node.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/fallback/umsgpack/umsgpack.py b/src/fallback/umsgpack/umsgpack.py index 68d5869a..97bfdf4c 100644 --- a/src/fallback/umsgpack/umsgpack.py +++ b/src/fallback/umsgpack/umsgpack.py @@ -49,7 +49,8 @@ License: MIT # pylint: disable=too-many-lines,too-many-branches,too-many-statements,global-statement,too-many-return-statements # pylint: disable=unused-argument -from six.moves import collections_abc as collections +from collections import OrderedDict +from six.moves.collections_abc import Hashable from six.moves import range as xrange import struct import sys @@ -752,7 +753,7 @@ def _unpack_map(code, fp, options): raise Exception("logic error, not map: 0x%02x" % six.byte2int(code)) d = {} if not options.get('use_ordered_dict') \ - else collections.OrderedDict() + else OrderedDict() for _ in xrange(length): # Unpack key k = _unpack(fp, options) @@ -760,7 +761,7 @@ def _unpack_map(code, fp, options): if isinstance(k, list): # Attempt to convert list into a hashable tuple k = _deep_list_to_tuple(k) - elif not isinstance(k, collections.Hashable): + elif not isinstance(k, Hashable): raise UnhashableKeyException( "encountered unhashable key: %s, %s" % (str(k), str(type(k)))) elif k in d: diff --git a/src/multiqueue.py b/src/multiqueue.py index 80598220..88b6a4dd 100644 --- a/src/multiqueue.py +++ b/src/multiqueue.py @@ -3,7 +3,7 @@ A queue with multiple internal subqueues. Elements are added into a random subqueue, and retrieval rotates """ -from six.moves.collections_abc import deque +from collections import deque from six.moves import queue diff --git a/src/network/node.py b/src/network/node.py index e580778b..4c532b81 100644 --- a/src/network/node.py +++ b/src/network/node.py @@ -1,7 +1,7 @@ """ Named tuples representing the network peers """ -from six.moves import collections_abc as collections +import collections Peer = collections.namedtuple('Peer', ['host', 'port']) Node = collections.namedtuple('Node', ['services', 'host', 'port'])