|
1 |
| -import collections |
2 | 1 | import abc
|
3 | 2 | import inspect
|
4 | 3 | import sys
|
| 4 | +try: |
| 5 | + from collections.abc import MutableSequence |
| 6 | +except ImportError: |
| 7 | + from collections import MutableSequence |
5 | 8 |
|
6 | 9 | import six
|
7 | 10 |
|
@@ -53,8 +56,7 @@ def is_number(s):
|
53 | 56 | def _check_if_has_indexable_children(item):
|
54 | 57 | if (not hasattr(item, 'children') or
|
55 | 58 | (not isinstance(item.children, Component) and
|
56 |
| - not isinstance(item.children, (tuple, |
57 |
| - collections.MutableSequence)))): |
| 59 | + not isinstance(item.children, (tuple, MutableSequence)))): |
58 | 60 |
|
59 | 61 | raise KeyError
|
60 | 62 |
|
@@ -153,7 +155,7 @@ def _get_set_or_delete(self, id, operation, new_item=None):
|
153 | 155 | pass
|
154 | 156 |
|
155 | 157 | # if children is like a list
|
156 |
| - if isinstance(self.children, (tuple, collections.MutableSequence)): |
| 158 | + if isinstance(self.children, (tuple, MutableSequence)): |
157 | 159 | for i, item in enumerate(self.children):
|
158 | 160 | # If the item itself is the one we're looking for
|
159 | 161 | if getattr(item, 'id', None) == id:
|
@@ -229,7 +231,7 @@ def traverse_with_paths(self):
|
229 | 231 | yield "\n".join(["[*] " + children_string, p]), t
|
230 | 232 |
|
231 | 233 | # children is a list of components
|
232 |
| - elif isinstance(children, (tuple, collections.MutableSequence)): |
| 234 | + elif isinstance(children, (tuple, MutableSequence)): |
233 | 235 | for idx, i in enumerate(children):
|
234 | 236 | list_path = "[{:d}] {:s} {}".format(
|
235 | 237 | idx,
|
@@ -262,7 +264,7 @@ def __len__(self):
|
262 | 264 | elif isinstance(self.children, Component):
|
263 | 265 | length = 1
|
264 | 266 | length += len(self.children)
|
265 |
| - elif isinstance(self.children, (tuple, collections.MutableSequence)): |
| 267 | + elif isinstance(self.children, (tuple, MutableSequence)): |
266 | 268 | for c in self.children:
|
267 | 269 | length += 1
|
268 | 270 | if isinstance(c, Component):
|
|
0 commit comments