diff --git a/openhtf/core/base_plugs.py b/openhtf/core/base_plugs.py index 6fddc73e..819a3467 100644 --- a/openhtf/core/base_plugs.py +++ b/openhtf/core/base_plugs.py @@ -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/phase_collections.py b/openhtf/core/phase_collections.py index 9772e574..0e0425a2 100644 --- a/openhtf/core/phase_collections.py +++ b/openhtf/core/phase_collections.py @@ -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 20e5eaa0..5463c13c 100644 --- a/openhtf/output/callbacks/__init__.py +++ b/openhtf/output/callbacks/__init__.py @@ -25,7 +25,7 @@ import shutil import tempfile import typing -from typing import BinaryIO, Callable, Iterator, Text, Union +from typing import BinaryIO, Callable, Iterator, Optional, Text, Union from openhtf import util from openhtf.core import test_record @@ -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/plugs/generic/serial_collection.py b/openhtf/plugs/generic/serial_collection.py index 3b1d85f3..aa3b3a51 100644 --- a/openhtf/plugs/generic/serial_collection.py +++ b/openhtf/plugs/generic/serial_collection.py @@ -18,6 +18,7 @@ import logging import threading +from typing import Optional from openhtf.core import base_plugs from openhtf.util import configuration @@ -57,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 a9244e85..1d062b26 100644 --- a/openhtf/plugs/user_input.py +++ b/openhtf/plugs/user_input.py @@ -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]]: