Skip to content

Commit c85fb06

Browse files
authored
Removed support for PY2. (#1009)
* Removed support for PY2. * Resolving imports from collections.abc module. * Use abc.ABC instead of abc.ABCMeta. * Adding back the line that converts bytes to strings.
1 parent 08e1d0d commit c85fb06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+172
-283
lines changed

bin/units_from_xls.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import sys
4545
import tempfile
4646

47-
import six
4847
import xlrd
4948

5049
# Column names for the columns we care about. This list must be populated in
@@ -163,10 +162,10 @@ def __call__(self, name_or_suffix):
163162
'15': 'FIFTEEN',
164163
'30': 'THIRTY',
165164
'\\': '_',
166-
six.unichr(160): '_', # NO-BREAK SPACE
167-
six.unichr(176): 'DEG_', # DEGREE SIGN
168-
six.unichr(186): 'DEG_', # MASCULINE ORDINAL INDICATOR
169-
six.unichr(8211): '_', # EN DASH
165+
chr(160): '_', # NO-BREAK SPACE
166+
chr(176): 'DEG_', # DEGREE SIGN
167+
chr(186): 'DEG_', # MASCULINE ORDINAL INDICATOR
168+
chr(8211): '_', # EN DASH
170169
}
171170

172171

@@ -222,7 +221,7 @@ def unit_defs_from_sheet(sheet, column_names):
222221
rows = sheet.get_rows()
223222

224223
# Find the indices for the columns we care about.
225-
for idx, cell in enumerate(six.next(rows)):
224+
for idx, cell in enumerate(next(rows)):
226225
if cell.value in column_names:
227226
col_indices[cell.value] = idx
228227

@@ -250,7 +249,7 @@ def unit_key_from_name(name):
250249
"""Return a legal python name for the given name for use as a unit key."""
251250
result = name
252251

253-
for old, new in six.iteritems(UNIT_KEY_REPLACEMENTS):
252+
for old, new in UNIT_KEY_REPLACEMENTS.items():
254253
result = result.replace(old, new)
255254

256255
# Collapse redundant underscores and convert to uppercase.

examples/all_the_things.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
from openhtf.output.callbacks import json_factory
2929
from openhtf.plugs import user_input
3030
from openhtf.util import units
31-
from six.moves import range
32-
from six.moves import zip
3331

3432

3533
@htf.plug(example=example_plugs.example_plug_configured)

openhtf/core/diagnoses_lib.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,14 @@ def main():
122122
"""
123123

124124
import abc
125+
from collections.abc import Iterable as CollectionsIterable
126+
import enum
125127
import logging
126128
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Text, Type, TYPE_CHECKING, Union
127129

128130
import attr
129-
import enum # pylint: disable=g-bad-import-order
130131
from openhtf.core import test_record
131132
from openhtf.util import data
132-
import six
133-
from six.moves import collections_abc
134133

135134
if TYPE_CHECKING:
136135
from openhtf.core import test_state # pylint: disable=g-import-not-at-top
@@ -204,8 +203,8 @@ def _convert_result(self,
204203
return
205204
elif isinstance(diagnosis_or_diagnoses, Diagnosis):
206205
yield self._verify_and_fix_diagnosis(diagnosis_or_diagnoses, diagnoser)
207-
elif (isinstance(diagnosis_or_diagnoses, six.string_types) or
208-
not isinstance(diagnosis_or_diagnoses, collections_abc.Iterable)):
206+
elif (isinstance(diagnosis_or_diagnoses, str) or
207+
not isinstance(diagnosis_or_diagnoses, CollectionsIterable)):
209208
raise InvalidDiagnosisError(
210209
'Diagnoser {} must return a single Diagnosis or an iterable '
211210
'of them.'.format(diagnoser.name))
@@ -328,7 +327,7 @@ def _check_definition(self) -> None:
328327
pass
329328

330329

331-
class BasePhaseDiagnoser(six.with_metaclass(abc.ABCMeta, _BaseDiagnoser)):
330+
class BasePhaseDiagnoser(_BaseDiagnoser, abc.ABC):
332331
"""Base class for using an object to define a Phase diagnoser."""
333332

334333
__slots__ = ()
@@ -377,7 +376,7 @@ def _check_definition(self) -> None:
377376
'PhaseDiagnoser run function not defined for {}'.format(self.name))
378377

379378

380-
class BaseTestDiagnoser(six.with_metaclass(abc.ABCMeta, _BaseDiagnoser)):
379+
class BaseTestDiagnoser(_BaseDiagnoser, abc.ABC):
381380
"""Base class for using an object to define a Test diagnoser."""
382381

383382
__slots__ = ()

openhtf/core/measurements.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def WidgetTestPhase(test):
7171
from openhtf.util import data
7272
from openhtf.util import units as util_units
7373
from openhtf.util import validators
74-
import six
7574
if typing.TYPE_CHECKING:
7675
from openhtf.core import diagnoses_lib
7776

@@ -147,7 +146,7 @@ def _coordinates_len(coordinates: Any) -> int:
147146
coordinates: any type, measurement coordinates for multidimensional
148147
measurements.
149148
"""
150-
if isinstance(coordinates, six.string_types):
149+
if isinstance(coordinates, str):
151150
return 1
152151
if hasattr(coordinates, '__len__'):
153152
return len(coordinates)
@@ -361,7 +360,7 @@ def validate_on(
361360
Returns:
362361
This measurement, used for chaining operations.
363362
"""
364-
for result, validator in six.iteritems(result_to_validator_mapping):
363+
for result, validator in result_to_validator_mapping.items():
365364
if not callable(validator):
366365
raise ValueError('Validator must be callable', validator)
367366
self.conditional_validators.append(
@@ -658,7 +657,7 @@ def is_value_set(self) -> bool:
658657

659658
def __iter__(self) -> Iterator[Any]:
660659
"""Iterate over items, allows easy conversion to a dict."""
661-
return iter(six.iteritems(self.value_dict))
660+
return iter(self.value_dict.items())
662661

663662
def __setitem__(self, coordinates: Any, value: Any) -> None:
664663
coordinates_len = _coordinates_len(coordinates)
@@ -717,14 +716,14 @@ def value(self) -> List[Any]:
717716
raise MeasurementNotSetError('Measurement not yet set', self.name)
718717
return [
719718
dimensions + (value,)
720-
for dimensions, value in six.iteritems(self.value_dict)
719+
for dimensions, value in self.value_dict.items()
721720
]
722721

723722
def basetype_value(self) -> List[Any]:
724723
if self._cached_basetype_values is None:
725724
self._cached_basetype_values = list(
726725
data.convert_to_base_types(coordinates + (value,))
727-
for coordinates, value in six.iteritems(self.value_dict))
726+
for coordinates, value in self.value_dict.items())
728727
return self._cached_basetype_values
729728

730729
def to_dataframe(self, columns: Any = None) -> Any:
@@ -791,7 +790,7 @@ def _assert_valid_key(self, name: Text) -> None:
791790
def __iter__(self) -> Iterator[Tuple[Text, Any]]:
792791
"""Extract each MeasurementValue's value."""
793792
return ((key, meas.measured_value.value)
794-
for key, meas in six.iteritems(self._measurements))
793+
for key, meas in self._measurements.items())
795794

796795
def _custom_setattr(self, name: Text, value: Any) -> None:
797796
if name == '_measurements':

openhtf/core/monitors.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,9 @@ def __init__(self, measurement_name: Text,
7676
self.extra_kwargs = extra_kwargs
7777

7878
def get_value(self) -> Any:
79-
if six.PY3:
80-
argspec = inspect.getfullargspec(self.monitor_desc.func)
81-
argspec_args = argspec.args
82-
argspec_keywords = argspec.varkw
83-
else:
84-
argspec = inspect.getargspec(self.monitor_desc.func) # pylint: disable=deprecated-method
85-
argspec_args = argspec.args
86-
argspec_keywords = argspec.keywords
79+
argspec = inspect.getfullargspec(self.monitor_desc.func)
80+
argspec_args = argspec.args
81+
argspec_keywords = argspec.varkw
8782
if argspec_keywords:
8883
# Monitor phase takes **kwargs, so just pass everything in.
8984
kwargs = self.extra_kwargs

openhtf/core/phase_branches.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@
1919
"""
2020

2121
import abc
22+
import enum
2223
from typing import Any, Callable, Dict, Iterator, Text, Tuple, TYPE_CHECKING, Union
2324

2425
import attr
25-
import enum # pylint: disable=g-bad-import-order
2626
from openhtf import util
2727
from openhtf.core import diagnoses_lib
2828
from openhtf.core import phase_collections
2929
from openhtf.core import phase_descriptor
3030
from openhtf.core import phase_nodes
3131
from openhtf.core import test_record
3232
from openhtf.util import data
33-
import six
3433

3534
if TYPE_CHECKING:
3635
from openhtf.core import test_state # pylint: disable=g-import-not-at-top
@@ -142,7 +141,7 @@ def should_run(self, diag_store: diagnoses_lib.DiagnosesStore) -> bool:
142141

143142

144143
@attr.s(slots=True, frozen=True)
145-
class Checkpoint(six.with_metaclass(abc.ABCMeta, phase_nodes.PhaseNode)):
144+
class Checkpoint(phase_nodes.PhaseNode, abc.ABC):
146145
"""Nodes that check for phase failures or if diagnoses were triggered.
147146
148147
When the condition for a checkpoint is triggered, a STOP or FAIL_SUBTEST

openhtf/core/phase_collections.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222

2323
import abc
2424
import collections
25+
from collections.abc import Iterable as CollectionsIterable
2526
from typing import Any, Callable, DefaultDict, Dict, Iterable, Iterator, List, Optional, Text, Tuple, Type, TypeVar, Union
2627

2728
import attr
2829
from openhtf import util
2930
from openhtf.core import base_plugs
3031
from openhtf.core import phase_descriptor
3132
from openhtf.core import phase_nodes
32-
import six
33-
from six.moves import collections_abc
3433

3534
NodeType = TypeVar('NodeType', bound=phase_nodes.PhaseNode)
3635
SequenceClassT = TypeVar('SequenceClassT', bound='PhaseSequence')
@@ -45,7 +44,7 @@ class DuplicateSubtestNamesError(Exception):
4544

4645
def _recursive_flatten(n: Any) -> Iterator[phase_nodes.PhaseNode]:
4746
"""Yields flattened phase nodes."""
48-
if isinstance(n, collections_abc.Iterable):
47+
if isinstance(n, CollectionsIterable):
4948
for it in n:
5049
for node in _recursive_flatten(it):
5150
yield node
@@ -62,8 +61,7 @@ def flatten(n: Any) -> List[phase_nodes.PhaseNode]:
6261
return list(_recursive_flatten(n))
6362

6463

65-
class PhaseCollectionNode(
66-
six.with_metaclass(abc.ABCMeta, phase_nodes.PhaseNode)):
64+
class PhaseCollectionNode(phase_nodes.PhaseNode, abc.ABC):
6765
"""Base class for a node that contains multiple other phase nodes."""
6866

6967
__slots__ = ()

openhtf/core/phase_descriptor.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
import openhtf.plugs
3838
from openhtf.util import data
3939

40-
import six
41-
4240
if TYPE_CHECKING:
4341
from openhtf.core import test_state # pylint: disable=g-import-not-at-top
4442

@@ -134,7 +132,7 @@ def format_strings(self, **kwargs: Any) -> 'PhaseOptions':
134132
return data.attr_copy(self, name=util.format_string(self.name, kwargs))
135133

136134
def update(self, **kwargs: Any) -> None:
137-
for key, value in six.iteritems(kwargs):
135+
for key, value in kwargs.items():
138136
setattr(self, key, value)
139137

140138
def __call__(self, phase_func: PhaseT) -> 'PhaseDescriptor':
@@ -245,14 +243,10 @@ def with_args(self, **kwargs: Any) -> 'PhaseDescriptor':
245243
Returns:
246244
Updated PhaseDescriptor.
247245
"""
248-
if six.PY3:
249-
argspec = inspect.getfullargspec(self.func)
250-
argspec_keywords = argspec.varkw
251-
else:
252-
argspec = inspect.getargspec(self.func) # pylint: disable=deprecated-method
253-
argspec_keywords = argspec.keywords
246+
argspec = inspect.getfullargspec(self.func)
247+
argspec_keywords = argspec.varkw
254248
known_arguments = {}
255-
for key, arg in six.iteritems(kwargs):
249+
for key, arg in kwargs.items():
256250
if key in argspec.args or argspec_keywords:
257251
known_arguments[key] = arg
258252

@@ -283,7 +277,7 @@ def with_plugs(self,
283277
plugs_by_name = {plug.name: plug for plug in self.plugs}
284278
new_plugs = {}
285279

286-
for name, sub_class in six.iteritems(subplugs):
280+
for name, sub_class in subplugs.items():
287281
original_plug = plugs_by_name.get(name)
288282
accept_substitute = True
289283
if original_plug is None:
@@ -341,12 +335,8 @@ def __call__(self,
341335
The return value from calling the underlying function.
342336
"""
343337
kwargs = {}
344-
if six.PY3:
345-
arg_info = inspect.getfullargspec(self.func)
346-
keywords = arg_info.varkw
347-
else:
348-
arg_info = inspect.getargspec(self.func) # pylint: disable=deprecated-method
349-
keywords = arg_info.keywords
338+
arg_info = inspect.getfullargspec(self.func)
339+
keywords = arg_info.varkw
350340
if arg_info.defaults is not None:
351341
for arg_name, arg_value in zip(arg_info.args[-len(arg_info.defaults):],
352342
arg_info.defaults):
@@ -419,7 +409,7 @@ def _maybe_make(
419409
"""Turn strings into Measurement objects if necessary."""
420410
if isinstance(meas, core_measurements.Measurement):
421411
return meas
422-
elif isinstance(meas, six.string_types):
412+
elif isinstance(meas, str):
423413
return core_measurements.Measurement(meas, **kwargs)
424414
raise core_measurements.InvalidMeasurementTypeError(
425415
'Expected Measurement or string', meas)

openhtf/core/phase_nodes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
from openhtf.core import base_plugs
2121
from openhtf.util import data
22-
import six
2322

2423
if TYPE_CHECKING:
2524
from openhtf.core import phase_descriptor # pylint: disable=g-import-not-at-top
@@ -28,7 +27,7 @@
2827
ApplyAllNodesT = TypeVar('ApplyAllNodesT', bound='PhaseNode')
2928

3029

31-
class PhaseNode(six.with_metaclass(abc.ABCMeta, object)):
30+
class PhaseNode(abc.ABC):
3231
"""Base class for all executable nodes in OpenHTF."""
3332

3433
__slots__ = ()

openhtf/core/test_descriptor.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@
5050
from openhtf.util import console_output
5151
from openhtf.util import logs
5252

53-
import six
54-
5553
CONF = configuration.CONF
5654

5755
_LOG = logging.getLogger(__name__)
@@ -247,7 +245,7 @@ def configure(self, **kwargs: Any) -> None:
247245
sys.stdout.write(CONF.help_text)
248246
sys.exit(0)
249247
logs.configure_logging()
250-
for key, value in six.iteritems(kwargs):
248+
for key, value in kwargs.items():
251249
setattr(self._test_options, key, value)
252250

253251
@classmethod

0 commit comments

Comments
 (0)