Browse Source

Merge "Handle move of ABCs to collections.abc"

tags/16.0.0.0b2
Zuul 1 month ago
parent
commit
63a28d40b2

+ 10
- 1
horizon/base.py View File

@@ -52,6 +52,15 @@ from horizon.utils import settings as utils_settings
52 52
 DEFAULT_PANEL_GROUP = 'default'
53 53
 LOG = logging.getLogger(__name__)
54 54
 
55
+# Python 3.8 removes the ability to import the abstract base classes from
56
+# 'collections', but 'collections.abc' is not present in Python 2.7
57
+# TODO(stephenfin): Remove when we drop support for Python 2.7
58
+# pylint: disable=ungrouped-imports
59
+if hasattr(collections, 'abc'):
60
+    from collections.abc import Iterable
61
+else:
62
+    from collections import Iterable
63
+
55 64
 
56 65
 def _decorate_urlconf(urlpatterns, decorator, *args, **kwargs):
57 66
     for pattern in urlpatterns:
@@ -591,7 +600,7 @@ class Dashboard(Registry, HorizonComponent):
591 600
         default_created = False
592 601
         for panel_set in self.panels:
593 602
             # Instantiate PanelGroup classes.
594
-            if not isinstance(panel_set, collections.Iterable) and \
603
+            if not isinstance(panel_set, Iterable) and \
595 604
                     issubclass(panel_set, PanelGroup):
596 605
                 panel_group = panel_set(self)
597 606
             # Check for nested tuples, and convert them to PanelGroups

+ 10
- 2
horizon/tables/base.py View File

@@ -48,6 +48,15 @@ from horizon.tables.actions import LinkAction
48 48
 from horizon.utils import html
49 49
 from horizon.utils import settings as utils_settings
50 50
 
51
+# Python 3.8 removes the ability to import the abstract base classes from
52
+# 'collections', but 'collections.abc' is not present in Python 2.7
53
+# TODO(stephenfin): Remove when we drop support for Python 2.7
54
+# pylint: disable=ungrouped-imports
55
+if hasattr(collections, 'abc'):
56
+    from collections.abc import Mapping
57
+else:
58
+    from collections import Mapping
59
+
51 60
 
52 61
 LOG = logging.getLogger(__name__)
53 62
 PALETTE = termcolors.PALETTES[termcolors.DEFAULT_PALETTE]
@@ -406,8 +415,7 @@ class Column(html.HTMLElement):
406 415
         if callable(self.transform):
407 416
             data = self.transform(datum)
408 417
         # Dict lookups
409
-        elif isinstance(datum, collections.Mapping) and \
410
-                self.transform in datum:
418
+        elif isinstance(datum, Mapping) and self.transform in datum:
411 419
             data = datum.get(self.transform)
412 420
         else:
413 421
             # Basic object lookups

+ 11
- 2
horizon/test/helpers.py View File

@@ -45,6 +45,15 @@ from django.contrib.staticfiles.testing \
45 45
 
46 46
 from horizon import middleware
47 47
 
48
+# Python 3.8 removes the ability to import the abstract base classes from
49
+# 'collections', but 'collections.abc' is not present in Python 2.7
50
+# TODO(stephenfin): Remove when we drop support for Python 2.7
51
+# pylint: disable=ungrouped-imports
52
+if hasattr(collections, 'abc'):
53
+    from collections.abc import Mapping
54
+else:
55
+    from collections import Mapping
56
+
48 57
 
49 58
 LOG = logging.getLogger(__name__)
50 59
 
@@ -335,8 +344,8 @@ class update_settings(django_test_utils.override_settings):
335 344
         if keep_dict:
336 345
             for key, new_value in kwargs.items():
337 346
                 value = getattr(settings, key, None)
338
-                if (isinstance(new_value, collections.Mapping) and
339
-                        isinstance(value, collections.Mapping)):
347
+                if (isinstance(new_value, Mapping) and
348
+                        isinstance(value, Mapping)):
340 349
                     copied = copy.copy(value)
341 350
                     copied.update(new_value)
342 351
                     kwargs[key] = copied

+ 10
- 1
openstack_dashboard/api/base.py View File

@@ -16,7 +16,7 @@
16 16
 #    License for the specific language governing permissions and limitations
17 17
 #    under the License.
18 18
 
19
-from collections import Sequence
19
+import collections
20 20
 import functools
21 21
 
22 22
 from django.conf import settings
@@ -25,6 +25,15 @@ import six
25 25
 
26 26
 from horizon import exceptions
27 27
 
28
+# Python 3.8 removes the ability to import the abstract base classes from
29
+# 'collections', but 'collections.abc' is not present in Python 2.7
30
+# TODO(stephenfin): Remove when we drop support for Python 2.7
31
+# pylint: disable=ungrouped-imports
32
+if hasattr(collections, 'abc'):
33
+    from collections.abc import Sequence
34
+else:
35
+    from collections import Sequence
36
+
28 37
 
29 38
 __all__ = ('APIResourceWrapper', 'APIDictWrapper',
30 39
            'get_service_from_catalog', 'url_for',)

+ 10
- 1
openstack_dashboard/api/glance.py View File

@@ -39,6 +39,15 @@ from horizon.utils.memoized import memoized
39 39
 from openstack_dashboard.api import base
40 40
 from openstack_dashboard.contrib.developer.profiler import api as profiler
41 41
 
42
+# Python 3.8 removes the ability to import the abstract base classes from
43
+# 'collections', but 'collections.abc' is not present in Python 2.7
44
+# TODO(stephenfin): Remove when we drop support for Python 2.7
45
+# pylint: disable=ungrouped-imports
46
+if hasattr(collections, 'abc'):
47
+    from collections.abc import Iterable
48
+else:
49
+    from collections import Iterable
50
+
42 51
 
43 52
 LOG = logging.getLogger(__name__)
44 53
 VERSIONS = base.APIVersionManager("image", preferred_version=2)
@@ -125,7 +134,7 @@ class Image(base.APIResourceWrapper):
125 134
         # for v2), self._apiresource is not iterable. In that case,
126 135
         # the properties are included in the apiresource dict, so
127 136
         # just return that dict.
128
-        if not isinstance(self._apiresource, collections.Iterable):
137
+        if not isinstance(self._apiresource, Iterable):
129 138
             return self._apiresource.to_dict()
130 139
         image_dict = super(Image, self).to_dict()
131 140
         image_dict['is_public'] = self.is_public

+ 10
- 6
openstack_dashboard/api/neutron.py View File

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

+ 10
- 1
openstack_dashboard/test/integration_tests/decorators.py View File

@@ -18,6 +18,15 @@ import testtools
18 18
 
19 19
 from openstack_dashboard.test.integration_tests import config
20 20
 
21
+# Python 3.8 removes the ability to import the abstract base classes from
22
+# 'collections', but 'collections.abc' is not present in Python 2.7
23
+# TODO(stephenfin): Remove when we drop support for Python 2.7
24
+# pylint: disable=ungrouped-imports
25
+if hasattr(collections, 'abc'):
26
+    from collections.abc import Iterable
27
+else:
28
+    from collections import Iterable
29
+
21 30
 
22 31
 def _is_test_method_name(method):
23 32
     return method.startswith('test_')
@@ -156,7 +165,7 @@ def skip_because(**kwargs):
156 165
     def actual_decoration(obj):
157 166
         skip_method = _get_skip_method(obj)
158 167
         bugs = kwargs.get("bugs")
159
-        if bugs and isinstance(bugs, collections.Iterable):
168
+        if bugs and isinstance(bugs, Iterable):
160 169
             for bug in bugs:
161 170
                 if not bug.isdigit():
162 171
                     raise ValueError("bug must be a valid bug number")

Loading…
Cancel
Save