From cca1b7d679d4aaf93ca61d7c4f36cdd87259e343 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Fri, 19 Nov 2021 23:26:00 -0800 Subject: [PATCH] mypy: Add types to terminal.py. --- tools/run-mypy | 1 - zulip_bots/zulip_bots/terminal.py | 14 ++++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/run-mypy b/tools/run-mypy index 3c47e21..9f0e982 100755 --- a/tools/run-mypy +++ b/tools/run-mypy @@ -23,7 +23,6 @@ exclude = [ "zulip_bots/zulip_bots/bots", "zulip_bots/zulip_bots/bots_unmaintained", # Excluded out of laziness: - "zulip_bots/zulip_bots/terminal.py", "zulip_bots/zulip_bots/simple_lib.py", "zulip_bots/zulip_bots/tests/test_lib.py", # Excluded because this is a self-contained script diff --git a/zulip_bots/zulip_bots/terminal.py b/zulip_bots/zulip_bots/terminal.py index 7eca1c8..5500bd4 100644 --- a/zulip_bots/zulip_bots/terminal.py +++ b/zulip_bots/zulip_bots/terminal.py @@ -9,7 +9,7 @@ from zulip_bots.simple_lib import MockMessageServer, TerminalBotHandler current_dir = os.path.dirname(os.path.abspath(__file__)) -def parse_args(): +def parse_args() -> argparse.Namespace: description = """ This tool allows you to test a bot using the terminal (and no Zulip server). @@ -32,15 +32,21 @@ def parse_args(): return args -def main(): +def main() -> None: args = parse_args() - bot_path, bot_name = resolve_bot_path(args.bot) + # NOTE: Use of only this implies bots from eg. registry cannot be explored in this way + result = resolve_bot_path(args.bot) + if result is None: + print(f"Cannot find find and import bot '{args.bot}'") + sys.exit(1) + + bot_path, bot_name = result bot_dir = os.path.dirname(bot_path) sys.path.insert(0, bot_dir) try: - lib_module = import_module_from_source(bot_path, bot_name) + lib_module = import_module_from_source(bot_path.as_posix(), bot_name) if lib_module is None: raise OSError except OSError: