mypy: Amend import_module_from_source, to pass with strict-optional.
Including additional error-reporting.
MODIFY
zulip_bots/zulip_bots/run.py
zulip_bots/zulip_bots/run.py
@@ -36,7 +36,10 @@ def import_module_from_source(path, name=None):
import importlib.util
spec = importlib.util.spec_from_file_location(name, path)
module = importlib.util.module_from_spec(spec)
- spec.loader.exec_module(module)
+ loader = spec.loader
+ if loader is None:
+ return None
+ loader.exec_module(module)
return module
@@ -123,7 +126,11 @@ def main():
bot_name = args.bot
if args.provision:
provision_bot(os.path.dirname(bot_path), args.force)
+
lib_module = import_module_from_source(bot_path, bot_name)
+ if lib_module is None:
+ print("ERROR: Could not load bot module. Exiting now.")
+ sys.exit(1)
if not args.quiet:
logging.basicConfig(stream=sys.stdout, level=logging.INFO)

MODIFY
zulip_bots/zulip_bots/terminal.py
zulip_bots/zulip_bots/terminal.py
@@ -40,6 +40,8 @@ def main():
try:
lib_module = import_module_from_source(bot_path, bot_name)
+ if lib_module is None:
+ raise IOError
except IOError:
print("Could not find and import bot '{}'".format(bot_name))
sys.exit(1)

mypy: Amend import_module_from_source, to pass with strict-optional.

Including additional error-reporting.