From 2fedb94f0ca31e7855b059d9e79be002d7ba7982 Mon Sep 17 00:00:00 2001 From: Adam King Date: Tue, 21 Sep 2021 14:00:11 -0400 Subject: [PATCH] cephadm: fix mypy complaints for ThreadedChildWatcher class Signed-off-by: Adam King (cherry picked from commit 8bdddfa02eea7331971c16a9f8806b8451f09c5b) --- src/cephadm/cephadm | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 477719bbec679..24c8e8498e012 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -1293,28 +1293,28 @@ if sys.version_info < (3, 8): def __init__(self) -> None: self._pid_counter = itertools.count(0) - self._threads = {} + self._threads: Dict[Any, Any] = {} - def is_active(self): + def is_active(self) -> bool: return True - def close(self): + def close(self) -> None: self._join_threads() - def _join_threads(self): + def _join_threads(self) -> None: """Internal: Join all non-daemon threads""" threads = [thread for thread in list(self._threads.values()) if thread.is_alive() and not thread.daemon] for thread in threads: thread.join() - def __enter__(self): + def __enter__(self) -> Any: return self - def __exit__(self, exc_type, exc_val, exc_tb): + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: pass - def __del__(self, _warn=warnings.warn): + def __del__(self, _warn: Any = warnings.warn) -> None: threads = [thread for thread in list(self._threads.values()) if thread.is_alive()] if threads: @@ -1322,7 +1322,7 @@ if sys.version_info < (3, 8): ResourceWarning, source=self) - def add_child_handler(self, pid, callback, *args): + def add_child_handler(self, pid: Any, callback: Any, *args: Any) -> None: loop = events.get_event_loop() thread = threading.Thread(target=self._do_waitpid, name=f'waitpid-{next(self._pid_counter)}', @@ -1331,16 +1331,16 @@ if sys.version_info < (3, 8): self._threads[pid] = thread thread.start() - def remove_child_handler(self, pid): + def remove_child_handler(self, pid: Any) -> bool: # asyncio never calls remove_child_handler() !!! # The method is no-op but is implemented because # abstract base classe requires it return True - def attach_loop(self, loop): + def attach_loop(self, loop: Any) -> None: pass - def _do_waitpid(self, loop, expected_pid, callback, args): + def _do_waitpid(self, loop: Any, expected_pid: Any, callback: Any, args: Any) -> None: assert expected_pid > 0 try: -- 2.39.5