From d6df2c20cbd02c405f8fa1ae2d8b7628ceece896 Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Fri, 16 Oct 2020 07:52:36 -0500 Subject: [PATCH] Remove collections.abc backwards compatibility The collections module moves some abstract classes into the abc submodules in py3. While we supported older versions of python, we needed to handle importing from either the old or new locations. Now that we only support runtimes that include the collections.abc module, we can remove the backwards compatibility handling we had for the old location. Change-Id: Idd106a8199fa586e0b34c054383d64218383c001 Signed-off-by: Sean McGinnis --- cinder/cmd/manage.py | 6 +----- cinder/objects/base.py | 10 +++------- cinder/objects/cleanable.py | 6 +----- .../netapp/dataontap/test_block_driver_interfaces.py | 7 ++----- 4 files changed, 7 insertions(+), 22 deletions(-) diff --git a/cinder/cmd/manage.py b/cinder/cmd/manage.py index d8de35084a5..bb7084d7b40 100644 --- a/cinder/cmd/manage.py +++ b/cinder/cmd/manage.py @@ -50,11 +50,7 @@ """CLI interface for cinder management.""" -try: - import collections.abc as collections -except ImportError: - import collections - +import collections.abc as collections import logging as python_logging import sys import time diff --git a/cinder/objects/base.py b/cinder/objects/base.py index 336afffbdae..1b04fe2683a 100644 --- a/cinder/objects/base.py +++ b/cinder/objects/base.py @@ -14,11 +14,7 @@ """Cinder common internal object model""" -try: - from collections.abc import Callable -except ImportError: - from collections import Callable - +from collections import abc import contextlib import datetime @@ -167,7 +163,7 @@ class CinderObjectRegistry(base.VersionedObjectRegistry): # If registering class has a callable initialization method, call it. if isinstance(getattr(cls, 'cinder_ovo_cls_init', None), - Callable): + abc.Callable): cls.cinder_ovo_cls_init() @@ -578,7 +574,7 @@ class CinderObjectSerializer(base.VersionedObjectSerializer): entity = self._process_iterable(context, self.serialize_entity, entity) elif (hasattr(entity, 'obj_to_primitive') and - isinstance(entity.obj_to_primitive, Callable)): + isinstance(entity.obj_to_primitive, abc.Callable)): # NOTE(dulek): Backport outgoing object to the capped version. backport_ver = self._get_capped_obj_version(entity) entity = entity.obj_to_primitive(backport_ver, self.manifest) diff --git a/cinder/objects/cleanable.py b/cinder/objects/cleanable.py index f3064bf96d7..10bf0f25550 100644 --- a/cinder/objects/cleanable.py +++ b/cinder/objects/cleanable.py @@ -13,11 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -try: - import collections.abc as collections -except ImportError: - import collections - +import collections.abc as collections import inspect import decorator diff --git a/cinder/tests/unit/volume/drivers/netapp/dataontap/test_block_driver_interfaces.py b/cinder/tests/unit/volume/drivers/netapp/dataontap/test_block_driver_interfaces.py index ad7c37ac314..0bb58de6bb9 100644 --- a/cinder/tests/unit/volume/drivers/netapp/dataontap/test_block_driver_interfaces.py +++ b/cinder/tests/unit/volume/drivers/netapp/dataontap/test_block_driver_interfaces.py @@ -13,10 +13,7 @@ # under the License. """Mock unit tests for the NetApp block storage driver interfaces""" -try: - from collections.abc import Callable -except ImportError: - from collections import Callable +from collections import abc from cinder.tests.unit import test from cinder.volume.drivers.netapp.dataontap import block_cmode @@ -56,4 +53,4 @@ class NetAppBlockStorageDriverInterfaceTestCase(test.TestCase): def _get_local_functions(self, obj): """Get function names of an object without superclass functions.""" return set([key for key, value in type(obj).__dict__.items() - if isinstance(value, Callable)]) + if isinstance(value, abc.Callable)])