Handle move of ABCs to collections.abc

Resolves the following warning:

  DeprecationWarning: Using or importing the ABCs from 'collections'
  instead of from 'collections.abc' is deprecated, and in 3.8 it will
  stop working

Change-Id: Ib2214e7560cda1ef510c08859d5ee0726eb66b7b
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2019-08-27 09:29:29 +01:00 committed by Akihiro Motoki
parent c82c955160
commit 4ece14b28a
7 changed files with 71 additions and 14 deletions

View File

@ -52,6 +52,15 @@ from horizon.utils import settings as utils_settings
DEFAULT_PANEL_GROUP = 'default'
LOG = logging.getLogger(__name__)
# Python 3.8 removes the ability to import the abstract base classes from
# 'collections', but 'collections.abc' is not present in Python 2.7
# TODO(stephenfin): Remove when we drop support for Python 2.7
# pylint: disable=ungrouped-imports
if hasattr(collections, 'abc'):
from collections.abc import Iterable
else:
from collections import Iterable
def _decorate_urlconf(urlpatterns, decorator, *args, **kwargs):
for pattern in urlpatterns:
@ -591,7 +600,7 @@ class Dashboard(Registry, HorizonComponent):
default_created = False
for panel_set in self.panels:
# Instantiate PanelGroup classes.
if not isinstance(panel_set, collections.Iterable) and \
if not isinstance(panel_set, Iterable) and \
issubclass(panel_set, PanelGroup):
panel_group = panel_set(self)
# Check for nested tuples, and convert them to PanelGroups

View File

@ -48,6 +48,15 @@ from horizon.tables.actions import LinkAction
from horizon.utils import html
from horizon.utils import settings as utils_settings
# Python 3.8 removes the ability to import the abstract base classes from
# 'collections', but 'collections.abc' is not present in Python 2.7
# TODO(stephenfin): Remove when we drop support for Python 2.7
# pylint: disable=ungrouped-imports
if hasattr(collections, 'abc'):
from collections.abc import Mapping
else:
from collections import Mapping
LOG = logging.getLogger(__name__)
PALETTE = termcolors.PALETTES[termcolors.DEFAULT_PALETTE]
@ -397,8 +406,7 @@ class Column(html.HTMLElement):
if callable(self.transform):
data = self.transform(datum)
# Dict lookups
elif isinstance(datum, collections.Mapping) and \
self.transform in datum:
elif isinstance(datum, Mapping) and self.transform in datum:
data = datum.get(self.transform)
else:
# Basic object lookups

View File

@ -45,6 +45,15 @@ from django.contrib.staticfiles.testing \
from horizon import middleware
# Python 3.8 removes the ability to import the abstract base classes from
# 'collections', but 'collections.abc' is not present in Python 2.7
# TODO(stephenfin): Remove when we drop support for Python 2.7
# pylint: disable=ungrouped-imports
if hasattr(collections, 'abc'):
from collections.abc import Mapping
else:
from collections import Mapping
LOG = logging.getLogger(__name__)
@ -335,8 +344,8 @@ class update_settings(django_test_utils.override_settings):
if keep_dict:
for key, new_value in kwargs.items():
value = getattr(settings, key, None)
if (isinstance(new_value, collections.Mapping) and
isinstance(value, collections.Mapping)):
if (isinstance(new_value, Mapping) and
isinstance(value, Mapping)):
copied = copy.copy(value)
copied.update(new_value)
kwargs[key] = copied

View File

@ -16,7 +16,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from collections import Sequence
import collections
import functools
from django.conf import settings
@ -25,6 +25,15 @@ import six
from horizon import exceptions
# Python 3.8 removes the ability to import the abstract base classes from
# 'collections', but 'collections.abc' is not present in Python 2.7
# TODO(stephenfin): Remove when we drop support for Python 2.7
# pylint: disable=ungrouped-imports
if hasattr(collections, 'abc'):
from collections.abc import Sequence
else:
from collections import Sequence
__all__ = ('APIResourceWrapper', 'APIDictWrapper',
'get_service_from_catalog', 'url_for',)

View File

@ -39,6 +39,15 @@ from horizon.utils.memoized import memoized
from openstack_dashboard.api import base
from openstack_dashboard.contrib.developer.profiler import api as profiler
# Python 3.8 removes the ability to import the abstract base classes from
# 'collections', but 'collections.abc' is not present in Python 2.7
# TODO(stephenfin): Remove when we drop support for Python 2.7
# pylint: disable=ungrouped-imports
if hasattr(collections, 'abc'):
from collections.abc import Iterable
else:
from collections import Iterable
LOG = logging.getLogger(__name__)
VERSIONS = base.APIVersionManager("image", preferred_version=2)
@ -125,7 +134,7 @@ class Image(base.APIResourceWrapper):
# for v2), self._apiresource is not iterable. In that case,
# the properties are included in the apiresource dict, so
# just return that dict.
if not isinstance(self._apiresource, collections.Iterable):
if not isinstance(self._apiresource, Iterable):
return self._apiresource.to_dict()
image_dict = super(Image, self).to_dict()
image_dict['is_public'] = self.is_public

View File

@ -40,6 +40,15 @@ from openstack_dashboard.api import nova
from openstack_dashboard.contrib.developer.profiler import api as profiler
from openstack_dashboard import policy
# Python 3.8 removes the ability to import the abstract base classes from
# 'collections', but 'collections.abc' is not present in Python 2.7
# TODO(stephenfin): Remove when we drop support for Python 2.7
# pylint: disable=ungrouped-imports
if hasattr(collections, 'abc'):
from collections.abc import Sequence
else:
from collections import Sequence
LOG = logging.getLogger(__name__)
@ -854,14 +863,9 @@ def list_resources_with_long_filters(list_method,
# filter_values) and do not consider other filter conditions
# which may be specified in **params.
# NOTE(pas-ha) this will produce a deprecation warning in Py37
# and will not work in Py38, and six.moves also does not support it
# (see https://github.com/benjaminp/six/issues/155).
# TODO(pas-ha) replace with collections.abc.Sequence
# after dropping py27 support in U release
if isinstance(filter_values, six.string_types):
filter_values = [filter_values]
elif not isinstance(filter_values, collections.Sequence):
elif not isinstance(filter_values, Sequence):
filter_values = list(filter_values)
# Length of each query filter is:

View File

@ -18,6 +18,15 @@ import testtools
from openstack_dashboard.test.integration_tests import config
# Python 3.8 removes the ability to import the abstract base classes from
# 'collections', but 'collections.abc' is not present in Python 2.7
# TODO(stephenfin): Remove when we drop support for Python 2.7
# pylint: disable=ungrouped-imports
if hasattr(collections, 'abc'):
from collections.abc import Iterable
else:
from collections import Iterable
def _is_test_method_name(method):
return method.startswith('test_')
@ -156,7 +165,7 @@ def skip_because(**kwargs):
def actual_decoration(obj):
skip_method = _get_skip_method(obj)
bugs = kwargs.get("bugs")
if bugs and isinstance(bugs, collections.Iterable):
if bugs and isinstance(bugs, Iterable):
for bug in bugs:
if not bug.isdigit():
raise ValueError("bug must be a valid bug number")