types: fix type annotations and remove novm annootations for llnl module

Apparently I forgot to do this in #34305.
This commit is contained in:
Todd Gamblin 2022-12-23 10:06:24 -08:00 committed by Harmen Stoppels
parent e8fa8c5f01
commit d100ac8923
2 changed files with 13 additions and 18 deletions

View File

@ -890,8 +890,8 @@ def load_module_from_file(module_name, module_path):
# This recipe is adapted from https://stackoverflow.com/a/67692/771663 # This recipe is adapted from https://stackoverflow.com/a/67692/771663
spec = importlib.util.spec_from_file_location(module_name, module_path) # novm spec = importlib.util.spec_from_file_location(module_name, module_path)
module = importlib.util.module_from_spec(spec) # novm module = importlib.util.module_from_spec(spec)
# The module object needs to exist in sys.modules before the # The module object needs to exist in sys.modules before the
# loader executes the module code. # loader executes the module code.
# #
@ -990,10 +990,9 @@ def enum(**kwargs):
def stable_partition( def stable_partition(
input_iterable, # type: Iterable input_iterable: Iterable,
predicate_fn, # type: Callable[[Any], bool] predicate_fn: Callable[[Any], bool],
): ) -> Tuple[List[Any], List[Any]]:
# type: (...) -> Tuple[List[Any], List[Any]]
"""Partition the input iterable according to a custom predicate. """Partition the input iterable according to a custom predicate.
Args: Args:
@ -1065,23 +1064,20 @@ class GroupedExceptionHandler(object):
"""A generic mechanism to coalesce multiple exceptions and preserve tracebacks.""" """A generic mechanism to coalesce multiple exceptions and preserve tracebacks."""
def __init__(self): def __init__(self):
self.exceptions = [] # type: List[Tuple[str, Exception, List[str]]] self.exceptions: List[Tuple[str, Exception, List[str]]] = []
def __bool__(self): def __bool__(self):
"""Whether any exceptions were handled.""" """Whether any exceptions were handled."""
return bool(self.exceptions) return bool(self.exceptions)
def forward(self, context): def forward(self, context: str) -> "GroupedExceptionForwarder":
# type: (str) -> GroupedExceptionForwarder
"""Return a contextmanager which extracts tracebacks and prefixes a message.""" """Return a contextmanager which extracts tracebacks and prefixes a message."""
return GroupedExceptionForwarder(context, self) return GroupedExceptionForwarder(context, self)
def _receive_forwarded(self, context, exc, tb): def _receive_forwarded(self, context: str, exc: Exception, tb: List[str]):
# type: (str, Exception, List[str]) -> None
self.exceptions.append((context, exc, tb)) self.exceptions.append((context, exc, tb))
def grouped_message(self, with_tracebacks=True): def grouped_message(self, with_tracebacks: bool = True) -> str:
# type: (bool) -> str
"""Print out an error message coalescing all the forwarded errors.""" """Print out an error message coalescing all the forwarded errors."""
each_exception_message = [ each_exception_message = [
"{0} raised {1}: {2}{3}".format( "{0} raised {1}: {2}{3}".format(
@ -1099,8 +1095,7 @@ class GroupedExceptionForwarder(object):
"""A contextmanager to capture exceptions and forward them to a """A contextmanager to capture exceptions and forward them to a
GroupedExceptionHandler.""" GroupedExceptionHandler."""
def __init__(self, context, handler): def __init__(self, context: str, handler: GroupedExceptionHandler):
# type: (str, GroupedExceptionHandler) -> None
self._context = context self._context = context
self._handler = handler self._handler = handler

View File

@ -21,12 +21,12 @@
import traceback import traceback
from contextlib import contextmanager from contextlib import contextmanager
from threading import Thread from threading import Thread
from types import ModuleType # novm from types import ModuleType
from typing import Optional # novm from typing import Optional
import llnl.util.tty as tty import llnl.util.tty as tty
termios = None # type: Optional[ModuleType] termios: Optional[ModuleType] = None
try: try:
import termios as term_mod import termios as term_mod