Skip to content

Commit

Permalink
Move some type hints from comments to the newer style
Browse files Browse the repository at this point in the history
  • Loading branch information
glados-verma committed Nov 14, 2024
1 parent 16941c3 commit f9209cf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
10 changes: 5 additions & 5 deletions openhtf/core/base_plugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions openhtf/core/phase_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions openhtf/output/callbacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions openhtf/plugs/generic/serial_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import logging
import threading
from typing import Optional

from openhtf.core import base_plugs
from openhtf.util import configuration
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions openhtf/plugs/user_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand Down

0 comments on commit f9209cf

Please sign in to comment.