From 4d48b33a41bd3d71ee30ceaaa1000d4b306adb63 Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Tue, 9 Apr 2019 16:43:16 -0500 Subject: [PATCH] Handle collections.abc deprecations The use of ABC classes directly from collections has been deprecated in 3.x versions of Python. The direction is to use the classes defined in collections.abc. Python 2.7 does not have this, but Python 3.8 will be dropping the backwards compatibility to use the old location. Six also does not have support for this yet, so in the mean time to make sure we don't run into issues as folks try to move to 3.8, and to get rid of deprecation warnings in logs, this handles importing from the preferred location and falls back if it not available. Change-Id: If67133813634f41d89ccdf0f6d6d5ffa66c97dd8 Signed-off-by: Sean McGinnis --- oslo_messaging/_drivers/common.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/oslo_messaging/_drivers/common.py b/oslo_messaging/_drivers/common.py index 54ba98b55..3fd777c06 100644 --- a/oslo_messaging/_drivers/common.py +++ b/oslo_messaging/_drivers/common.py @@ -15,7 +15,13 @@ # License for the specific language governing permissions and limitations # under the License. -import collections +# TODO(smcginnis) update this once six has support for collections.abc +# (https://github.com/benjaminp/six/pull/241) or clean up once we drop py2.7. +try: + from collections.abc import Mapping +except ImportError: + from collections import Mapping + import copy import logging import sys @@ -481,7 +487,7 @@ class ConnectionContext(Connection): raise InvalidRPCConnectionReuse() -class ConfigOptsProxy(collections.Mapping): +class ConfigOptsProxy(Mapping): """Proxy for oslo_config.cfg.ConfigOpts. Values from the query part of the transport url (if they are both present @@ -518,7 +524,7 @@ class ConfigOptsProxy(collections.Mapping): def __len__(self): return len(self._conf) - class GroupAttrProxy(collections.Mapping): + class GroupAttrProxy(Mapping): """Internal helper proxy for oslo_config.cfg.ConfigOpts.GroupAttr.""" _VOID_MARKER = object()