diff --git a/openhtf/__init__.py b/openhtf/__init__.py index d6b490462..84abf4536 100644 --- a/openhtf/__init__.py +++ b/openhtf/__init__.py @@ -15,7 +15,6 @@ import importlib.metadata import signal -import typing from openhtf.core import phase_executor from openhtf.core import test_record diff --git a/openhtf/core/base_plugs.py b/openhtf/core/base_plugs.py index dbfdd55a0..819a34672 100644 --- a/openhtf/core/base_plugs.py +++ b/openhtf/core/base_plugs.py @@ -94,7 +94,7 @@ def __init__(self, my_config_key) """ import logging -from typing import Any, Dict, Set, Text, Type, Union +from typing import Any, Dict, Text, Type, Union import attr @@ -128,17 +128,17 @@ def tearDown(self): via TestApi. """ # Override this to True in subclasses to support remote Plug access. - enable_remote = False # type: bool + enable_remote: bool = False # Allow explicitly disabling remote access to specific attributes. - disable_remote_attrs = set() # type: Set[Text] + disable_remote_attrs = set() # Override this to True in subclasses to support using with_plugs with this # plug without needing to use placeholder. This will only affect the classes # that explicitly define this; subclasses do not share the declaration. - auto_placeholder = False # type: bool + auto_placeholder: bool = False # Default logger to be used only in __init__ of subclasses. # This is overwritten both on the class and the instance so don't store # a copy of it anywhere. - logger = _LOG # type: logging.Logger + logger: logging.Logger = _LOG @util.classproperty def placeholder(cls) -> 'PlugPlaceholder': # pylint: disable=no-self-argument @@ -185,7 +185,7 @@ class FrontendAwareBasePlug(BasePlug, util.SubscribableStateMixin): Since the Station API runs in a separate thread, the _asdict() method of frontend-aware plugs should be written with thread safety in mind. """ - enable_remote = True # type: bool + enable_remote: bool = True @attr.s(slots=True, frozen=True) diff --git a/openhtf/core/diagnoses_lib.py b/openhtf/core/diagnoses_lib.py index ae1424006..f8adbf1ff 100644 --- a/openhtf/core/diagnoses_lib.py +++ b/openhtf/core/diagnoses_lib.py @@ -324,7 +324,6 @@ def possible_results(self) -> List[Text]: def _check_definition(self) -> None: """Internal function to verify that the diagnoser is completely defined.""" - pass class BasePhaseDiagnoser(_BaseDiagnoser, abc.ABC): diff --git a/openhtf/core/measurements.py b/openhtf/core/measurements.py index 9dbbc5a6e..d7ac74c2a 100644 --- a/openhtf/core/measurements.py +++ b/openhtf/core/measurements.py @@ -63,7 +63,6 @@ def WidgetTestPhase(test): import enum import functools import logging -import time import typing from typing import Any, Callable, Dict, Iterator, List, Optional, Text, Tuple, Union diff --git a/openhtf/core/phase_collections.py b/openhtf/core/phase_collections.py index 97a3ade36..0e0425a25 100644 --- a/openhtf/core/phase_collections.py +++ b/openhtf/core/phase_collections.py @@ -23,7 +23,7 @@ import abc import collections from collections.abc import Iterable as CollectionsIterable -from typing import Any, Callable, DefaultDict, Dict, Iterable, Iterator, List, Optional, Text, Tuple, Type, TypeVar, Union +from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Text, Tuple, Type, TypeVar, Union import attr from openhtf import util @@ -221,16 +221,18 @@ def check_for_duplicate_subtest_names(sequence: PhaseSequence): Raises: DuplicateSubtestNamesError: when duplicate subtest names are found. """ - names_to_subtests = collections.defaultdict( - list) # type: DefaultDict[Text, List[Subtest]] + names_to_subtests: collections.defaultdict[str, list[Subtest]] = ( + collections.defaultdict(list) + ) for subtest in sequence.filter_by_type(Subtest): names_to_subtests[subtest.name].append(subtest) - duplicates = [] # type: List[Text] + duplicates: list[str] = [] for name, subtests in names_to_subtests.items(): if len(subtests) > 1: - duplicates.append('Name "{}" used by multiple subtests: {}'.format( - name, subtests)) + duplicates.append( + 'Name "{}" used by multiple subtests: {}'.format(name, subtests) + ) if not duplicates: return duplicates.sort() diff --git a/openhtf/output/callbacks/__init__.py b/openhtf/output/callbacks/__init__.py index 467d42ebf..5463c13ce 100644 --- a/openhtf/output/callbacks/__init__.py +++ b/openhtf/output/callbacks/__init__.py @@ -80,8 +80,8 @@ class OutputToFile(object): def __init__(self, filename_pattern_or_file: Union[Text, Callable[..., Text], BinaryIO]): - self.filename_pattern = None # type: Optional[Union[Text, Callable[..., Text]]] - self.output_file = None # type: Optional[BinaryIO] + self.filename_pattern: Optional[Union[Text, Callable[..., Text]]] = None + self.output_file: Optional[BinaryIO] = None if (isinstance(filename_pattern_or_file, str) or callable(filename_pattern_or_file)): self.filename_pattern = filename_pattern_or_file # pytype: disable=annotation-type-mismatch diff --git a/openhtf/output/servers/pub_sub.py b/openhtf/output/servers/pub_sub.py index dc2acfdcd..b900f4b82 100644 --- a/openhtf/output/servers/pub_sub.py +++ b/openhtf/output/servers/pub_sub.py @@ -67,8 +67,6 @@ def on_close(self): def on_subscribe(self, info): """Called when new clients subscribe. Subclasses can override.""" - pass def on_unsubscribe(self): """Called when clients unsubscribe. Subclasses can override.""" - pass diff --git a/openhtf/plugs/generic/serial_collection.py b/openhtf/plugs/generic/serial_collection.py index 754709f2a..aa3b3a51a 100644 --- a/openhtf/plugs/generic/serial_collection.py +++ b/openhtf/plugs/generic/serial_collection.py @@ -58,10 +58,10 @@ class SerialCollectionPlug(base_plugs.BasePlug): # Serial library can raise these exceptions SERIAL_EXCEPTIONS = (serial.SerialException, ValueError) - _serial = None # type: serial.Serial - _serial_port = None # type: int - _collect = None # type: bool - _collection_thread = None # type: Optional[threading.Thread] + _serial: Optional[serial.Serial] = None + _serial_port: Optional[int] = None + _collect: Optional[bool] = None + _collection_thread: Optional[threading.Thread] = None @CONF.inject_positional_args def __init__(self, serial_collection_port, serial_collection_baud): diff --git a/openhtf/plugs/user_input.py b/openhtf/plugs/user_input.py index 0a323b9af..1d062b265 100644 --- a/openhtf/plugs/user_input.py +++ b/openhtf/plugs/user_input.py @@ -24,7 +24,7 @@ import select import sys import threading -from typing import Any, Callable, Dict, Optional, Text, Tuple, Union +from typing import Any, Callable, Dict, Optional, Text, Union import uuid import attr @@ -142,10 +142,10 @@ class UserInput(base_plugs.FrontendAwareBasePlug): def __init__(self): super(UserInput, self).__init__() - self.last_response = None # type: Optional[Tuple[Text, Text]] - self._prompt = None # type: Optional[Prompt] - self._console_prompt = None # type: Optional[ConsolePrompt] - self._response = None # type: Optional[Text] + self.last_response: Optional[tuple[str, str]] = None + self._prompt: Optional[Prompt] = None + self._console_prompt: Optional[ConsolePrompt] = None + self._response: Optional[Text] = None self._cond = threading.Condition(threading.RLock()) def _asdict(self) -> Optional[Dict[Text, Any]]: diff --git a/openhtf/util/__init__.py b/openhtf/util/__init__.py index 4f735e33f..b21626cc7 100644 --- a/openhtf/util/__init__.py +++ b/openhtf/util/__init__.py @@ -18,7 +18,7 @@ import threading import time import typing -from typing import Any, Callable, Dict, Iterator, Optional, Text, Tuple, Type, TypeVar, Union +from typing import Any, Callable, Dict, Iterator, Optional, Text, Tuple, TypeVar import weakref import attr diff --git a/openhtf/util/logs.py b/openhtf/util/logs.py index 6b8370258..02f9a0b6c 100644 --- a/openhtf/util/logs.py +++ b/openhtf/util/logs.py @@ -110,7 +110,6 @@ def MyPhase(test, helper): from openhtf.util import argv from openhtf.util import console_output from openhtf.util import functions -from openhtf.util import threads # The number of v's provided as command line arguments to control verbosity. # Will be overridden if the ARG_PARSER below parses the -v argument. diff --git a/openhtf/util/test.py b/openhtf/util/test.py index 1d9d8835d..611e10cf2 100644 --- a/openhtf/util/test.py +++ b/openhtf/util/test.py @@ -126,7 +126,6 @@ def test_multiple(self, mock_my_plug): assertMeasurementFail(phase_or_test_rec, measurement) """ -import collections from collections.abc import Callable as CollectionsCallable, Iterator import functools import inspect diff --git a/openhtf/util/threads.py b/openhtf/util/threads.py index 092f5ea91..5e64cae95 100644 --- a/openhtf/util/threads.py +++ b/openhtf/util/threads.py @@ -13,8 +13,6 @@ # limitations under the License. """Thread library defining a few helpers.""" -import _thread -import contextlib import cProfile import ctypes import functools diff --git a/openhtf/util/validators.py b/openhtf/util/validators.py index 320180533..7c1d83648 100644 --- a/openhtf/util/validators.py +++ b/openhtf/util/validators.py @@ -71,7 +71,7 @@ def MyPhase(test: htf.TestApi) -> None: import math import numbers import re -from typing import Callable, Dict, Optional, Type, TypeVar, Union +from typing import Callable, Dict, Optional, Union from openhtf import util diff --git a/openhtf/util/xmlrpcutil.py b/openhtf/util/xmlrpcutil.py index 1f6b689c1..8e9751abb 100644 --- a/openhtf/util/xmlrpcutil.py +++ b/openhtf/util/xmlrpcutil.py @@ -16,7 +16,6 @@ from collections.abc import Callable import http.client import socketserver -import sys import threading import xmlrpc.client import xmlrpc.server diff --git a/test/core/measurements_test.py b/test/core/measurements_test.py index 17aa533cb..d1d53a4d0 100644 --- a/test/core/measurements_test.py +++ b/test/core/measurements_test.py @@ -19,7 +19,6 @@ """ import collections -import unittest from unittest import mock import openhtf as htf diff --git a/test/output/callbacks/callbacks_test.py b/test/output/callbacks/callbacks_test.py index ea81ec29b..faa22326f 100644 --- a/test/output/callbacks/callbacks_test.py +++ b/test/output/callbacks/callbacks_test.py @@ -20,7 +20,6 @@ import io import json -import unittest import openhtf as htf from openhtf import util diff --git a/test/output/callbacks/mfg_inspector_test.py b/test/output/callbacks/mfg_inspector_test.py index 4f562fc20..ee19e5927 100644 --- a/test/output/callbacks/mfg_inspector_test.py +++ b/test/output/callbacks/mfg_inspector_test.py @@ -19,7 +19,6 @@ """ import collections import io -import unittest from unittest import mock import openhtf as htf diff --git a/test/phase_descriptor_test.py b/test/phase_descriptor_test.py index 727513593..29c84e086 100644 --- a/test/phase_descriptor_test.py +++ b/test/phase_descriptor_test.py @@ -30,7 +30,6 @@ def plain_func(): """Plain Docstring.""" - pass def normal_test_phase(): diff --git a/test/plugs/plugs_test.py b/test/plugs/plugs_test.py index 6325c7084..eaaedfd63 100644 --- a/test/plugs/plugs_test.py +++ b/test/plugs/plugs_test.py @@ -14,7 +14,6 @@ import threading import time -import unittest from openhtf import plugs from openhtf.core import base_plugs diff --git a/test/test_state_test.py b/test/test_state_test.py index b7f13e7f4..1ec948934 100644 --- a/test/test_state_test.py +++ b/test/test_state_test.py @@ -16,7 +16,6 @@ import logging import sys import tempfile -import unittest from unittest import mock from absl.testing import parameterized @@ -37,7 +36,6 @@ @openhtf.PhaseOptions(name='test_phase') def test_phase(): """Test docstring.""" - pass PHASE_STATE_BASE_TYPE_INITIAL = { diff --git a/test/util/text_test.py b/test/util/text_test.py index ff684d207..f3b8edbad 100644 --- a/test/util/text_test.py +++ b/test/util/text_test.py @@ -17,7 +17,6 @@ import sys import types import typing -import unittest from unittest import mock from absl.testing import parameterized