From ac92e047c10bcb246589a2c3c23626ad720008e8 Mon Sep 17 00:00:00 2001 From: Mads Jensen Date: Sun, 30 Jan 2022 14:46:45 +0100 Subject: [PATCH] Remove use of OrderedDict in various places (#1483) * Remove use of OrderedDict in Connection.info. * Remove remnant use of collections.OrderedDict * Undo QoS._delivered move to Python standard dictionary. This requires more work to convert, due to a hack in how the dictionary is used. * Undo LRUCache.data to dict conversion. It's also problematic, and caused tests to fail. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Revert QoS._delivered comment chagne. * Update comment Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- kombu/connection.py | 3 +-- kombu/transport/qpid.py | 7 +++---- kombu/transport/virtual/base.py | 2 ++ t/unit/transport/test_qpid.py | 3 +-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/kombu/connection.py b/kombu/connection.py index 3ad84645..03b3161d 100644 --- a/kombu/connection.py +++ b/kombu/connection.py @@ -2,7 +2,6 @@ import os import socket -from collections import OrderedDict from contextlib import contextmanager from itertools import count, cycle from operator import itemgetter @@ -658,7 +657,7 @@ class Connection: def info(self): """Get connection info.""" - return OrderedDict(self._info()) + return dict(self._info()) def __eqhash__(self): return HashedSeq(self.transport_cls, self.hostname, self.userid, diff --git a/kombu/transport/qpid.py b/kombu/transport/qpid.py index b0f8df13..2b2d1b18 100644 --- a/kombu/transport/qpid.py +++ b/kombu/transport/qpid.py @@ -92,7 +92,6 @@ import socket import ssl import sys import uuid -from collections import OrderedDict from gettext import gettext as _ from queue import Empty from time import monotonic @@ -189,7 +188,7 @@ class QoS: def __init__(self, session, prefetch_count=1): self.session = session self.prefetch_count = 1 - self._not_yet_acked = OrderedDict() + self._not_yet_acked = {} def can_consume(self): """Return True if the :class:`Channel` can consume more messages. @@ -229,8 +228,8 @@ class QoS: """Append message to the list of un-ACKed messages. Add a message, referenced by the delivery_tag, for ACKing, - rejecting, or getting later. Messages are saved into an - :class:`collections.OrderedDict` by delivery_tag. + rejecting, or getting later. Messages are saved into a + dict by delivery_tag. :param message: A received message that has not yet been ACKed. :type message: qpid.messaging.Message diff --git a/kombu/transport/virtual/base.py b/kombu/transport/virtual/base.py index d27cb375..1e18caa6 100644 --- a/kombu/transport/virtual/base.py +++ b/kombu/transport/virtual/base.py @@ -177,6 +177,8 @@ class QoS: self.channel = channel self.prefetch_count = prefetch_count or 0 + # Standard Python dictionaries do not support setting attributes + # on the object, hence the use of OrderedDict self._delivered = OrderedDict() self._delivered.restored = False self._dirty = set() diff --git a/t/unit/transport/test_qpid.py b/t/unit/transport/test_qpid.py index d3866364..95071e97 100644 --- a/t/unit/transport/test_qpid.py +++ b/t/unit/transport/test_qpid.py @@ -4,7 +4,6 @@ import ssl import sys import time import uuid -from collections import OrderedDict from collections.abc import Callable from itertools import count from queue import Empty @@ -57,7 +56,7 @@ class test_QoS__init__: assert qos_limit_two.prefetch_count == 1 def test__init___not_yet_acked_is_initialized(self): - assert isinstance(self.qos._not_yet_acked, OrderedDict) + assert isinstance(self.qos._not_yet_acked, dict) @pytest.mark.skip(reason='Not supported in Python3')