From 79fca6c5e50037aa455628745f1a1fa94cfb550c Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 11 Jul 2023 07:13:16 +0000 Subject: [PATCH] sane-ip-reconnect: add type annotations to compound types --- pkgs/additional/sane-scripts/src/sane-ip-reconnect | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/additional/sane-scripts/src/sane-ip-reconnect b/pkgs/additional/sane-scripts/src/sane-ip-reconnect index 40af582d..33406c0b 100755 --- a/pkgs/additional/sane-scripts/src/sane-ip-reconnect +++ b/pkgs/additional/sane-scripts/src/sane-ip-reconnect @@ -19,7 +19,7 @@ def rm_color(stdout: str) -> str: def rm_heading(stdout: str) -> str: return "\n".join(stdout.split("\n")[4:]) -def extract_columns(stdout: str) -> list: +def extract_columns(stdout: str) -> list[tuple[str, str]]: " split each line into two fields " lines = stdout.split("\n") items = [] @@ -38,7 +38,7 @@ def extract_columns(stdout: str) -> list: logger.debug(f"parsed iwctl output: {items!r}") return items -def iwctl(args: list, sudo: bool = False) -> str: +def iwctl(args: list[str], sudo: bool = False) -> str: cmd = [ "iwctl" ] + args if sudo: cmd = [ "sudo" ] + cmd @@ -52,21 +52,21 @@ def scan() -> None: iwctl(["station", "wlan0", "scan"], sudo=True) time.sleep(5) # give time for adapter to see networks -def get_known() -> list: +def get_known() -> list[str]: stdout = iwctl(["known-networks", "list"]) stdout = rm_color(stdout) stdout = rm_heading(stdout) logging.debug(f"iwctl known-networks list: got: {stdout}") return [name for (name, date) in extract_columns(stdout)] -def get_visible() -> list: +def get_visible() -> list[tuple[str, int]]: stdout = iwctl(["station", "wlan0", "get-networks", "rssi-dbms"]) stdout = rm_color(stdout) stdout = rm_heading(stdout) logging.debug(f"iwctl station wlan0 get-networks rssi-dbms: got: {stdout}") return [(name, int(strength)) for (name, strength) in extract_columns(stdout)] -def choose_best(visible: list, known: list) -> str: +def choose_best(visible: list[tuple[str, int]], known: list[str]) -> str: candidates = [(name, strength) for (name, strength) in visible if name in known] # the least-negative RSSI is the best return max(candidates, key=lambda c: c[1])[0] if candidates else None