Skip to content

Commit 310b64d

Browse files
author
wallacbe
authored
update collections.abc DeprecationWarning project wide (#957)
1 parent d9c4b92 commit 310b64d

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

openhtf/core/diagnoses_lib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def main():
131131
from openhtf.core import phase_descriptor
132132
from openhtf.util import data
133133
import six
134+
from six.moves import collections_abc
134135

135136

136137
class DiagnoserError(Exception):
@@ -201,7 +202,7 @@ def _convert_result(self, diagnosis_or_diagnoses, diagnoser):
201202
elif isinstance(diagnosis_or_diagnoses, Diagnosis):
202203
yield self._verify_and_fix_diagnosis(diagnosis_or_diagnoses, diagnoser)
203204
elif (isinstance(diagnosis_or_diagnoses, six.string_types) or
204-
not isinstance(diagnosis_or_diagnoses, collections.Iterable)):
205+
not isinstance(diagnosis_or_diagnoses, collections_abc.Iterable)):
205206
raise InvalidDiagnosisError(
206207
'Diagnoser {} must return a single Diagnosis or an iterable '
207208
'of them.'.format(diagnoser.name))

openhtf/core/phase_group.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
terminal if any of its Phases or further nested PhaseGroups are also terminal.
3636
"""
3737

38-
import collections
3938
import functools
4039

4140
import mutablerecords
4241

4342
from openhtf.core import phase_descriptor
4443
from openhtf.core import test_record
44+
from six.moves import collections_abc
4545

4646

4747
class PhaseGroup(mutablerecords.Record(
@@ -130,7 +130,7 @@ def combine(self, other, name=None):
130130
def wrap(self, main_phases, name=None):
131131
"""Returns PhaseGroup with additional main phases."""
132132
new_main = list(self.main)
133-
if isinstance(main_phases, collections.Iterable):
133+
if isinstance(main_phases, collections_abc.Iterable):
134134
new_main.extend(main_phases)
135135
else:
136136
new_main.append(main_phases)
@@ -212,7 +212,7 @@ def flatten_phases_and_groups(phases_or_groups):
212212
for phase in phases_or_groups:
213213
if isinstance(phase, PhaseGroup):
214214
ret.append(phase.flatten())
215-
elif isinstance(phase, collections.Iterable):
215+
elif isinstance(phase, collections_abc.Iterable):
216216
ret.extend(flatten_phases_and_groups(phase))
217217
else:
218218
ret.append(phase_descriptor.PhaseDescriptor.wrap_or_copy(phase))
@@ -236,7 +236,7 @@ def optionally_with_args(phase, **kwargs):
236236
"""
237237
if isinstance(phase, PhaseGroup):
238238
return phase.with_args(**kwargs)
239-
if isinstance(phase, collections.Iterable):
239+
if isinstance(phase, collections_abc.Iterable):
240240
return [optionally_with_args(p, **kwargs) for p in phase]
241241

242242
if not isinstance(phase, phase_descriptor.PhaseDescriptor):
@@ -267,7 +267,7 @@ def optionally_with_plugs(phase, **subplugs):
267267
"""
268268
if isinstance(phase, PhaseGroup):
269269
return phase.with_plugs(**subplugs)
270-
if isinstance(phase, collections.Iterable):
270+
if isinstance(phase, collections_abc.Iterable):
271271
return [optionally_with_plugs(p, **subplugs) for p in phase]
272272

273273
if not isinstance(phase, phase_descriptor.PhaseDescriptor):

openhtf/util/data.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
little easier to work with them.
1919
"""
2020

21-
import collections
2221
import difflib
2322
import itertools
2423
import logging
@@ -35,6 +34,8 @@
3534

3635
from enum import Enum
3736
import six
37+
from six.moves import collections_abc
38+
3839

3940
# Used by convert_to_base_types().
4041
PASSTHROUGH_TYPES = {bool, bytes, int, long, type(None), unicode}
@@ -212,7 +213,7 @@ def _sizeof(current_obj):
212213
if isinstance(current_obj, dict):
213214
size += sum(map(sizeof, itertools.chain.from_iterable(
214215
six.iteritems(current_obj))))
215-
elif (isinstance(current_obj, collections.Iterable) and
216+
elif (isinstance(current_obj, collections_abc.Iterable) and
216217
not isinstance(current_obj, six.string_types)):
217218
size += sum(sizeof(item) for item in current_obj)
218219
elif isinstance(current_obj, records.RecordClass):

openhtf/util/test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ def test_multiple(self, mock_my_plug):
112112
assertMeasurementFail(phase_or_test_rec, measurement)
113113
"""
114114

115-
import collections
116115
import functools
117116
import inspect
118117
import logging
@@ -134,6 +133,8 @@ def test_multiple(self, mock_my_plug):
134133
from openhtf.plugs import device_wrapping
135134
from openhtf.util import logs
136135
import six
136+
from six.moves import collections_abc
137+
137138

138139
logs.CLI_LOGGING_VERBOSITY = 2
139140

@@ -142,7 +143,7 @@ class InvalidTestError(Exception):
142143
"""Raised when there's something invalid about a test."""
143144

144145

145-
class PhaseOrTestIterator(collections.Iterator):
146+
class PhaseOrTestIterator(collections_abc.Iterator):
146147

147148
def __init__(self, test_case, iterator, mock_plugs,
148149
phase_user_defined_state, phase_diagnoses):
@@ -266,7 +267,7 @@ def __next__(self):
266267
phase_or_test = self.iterator.send(self.last_result)
267268
if isinstance(phase_or_test, openhtf.Test):
268269
self.last_result, failure_message = self._handle_test(phase_or_test)
269-
elif not isinstance(phase_or_test, collections.Callable):
270+
elif not isinstance(phase_or_test, collections_abc.Callable):
270271
raise InvalidTestError(
271272
'methods decorated with patch_plugs must yield Test instances or '
272273
'individual test phases', phase_or_test)
@@ -279,7 +280,7 @@ def next(self):
279280
phase_or_test = self.iterator.send(self.last_result)
280281
if isinstance(phase_or_test, openhtf.Test):
281282
self.last_result, failure_message = self._handle_test(phase_or_test)
282-
elif not isinstance(phase_or_test, collections.Callable):
283+
elif not isinstance(phase_or_test, collections_abc.Callable):
283284
raise InvalidTestError(
284285
'methods decorated with patch_plugs must yield Test instances or '
285286
'individual test phases', phase_or_test)

openhtf/util/xmlrpcutil.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import threading
2222
import xmlrpc.client
2323
import collections
24+
from six.moves import collections_abc
25+
2426

2527
DEFAULT_PROXY_TIMEOUT_S = 3
2628

@@ -90,7 +92,7 @@ def __init__(self, *args, **kwargs):
9092

9193
def __getattr__(self, attr):
9294
method = super(LockedProxyMixin, self).__getattr__(attr)
93-
if isinstance(method, collections.Callable):
95+
if isinstance(method, collections_abc.Callable):
9496
# xmlrpc doesn't support **kwargs, so only accept *args.
9597
def _wrapper(*args):
9698
with self._lock:

0 commit comments

Comments
 (0)