mypy: Fix exec_module type: ignore comments.
MODIFY
zulip_bots/zulip_bots/bots/witai/witai.py
zulip_bots/zulip_bots/bots/witai/witai.py
from typing import Dict, Any, Optional, Callable
from zulip_bots.lib import BotHandler
import wit
+import importlib.abc
import importlib.util
class WitaiHandler:
@@ -76,10 +77,10 @@ def get_handle(location: str) -> Optional[Callable[[Dict[str, Any]], Optional[st
spec = importlib.util.spec_from_file_location('module.name', location)
handler = importlib.util.module_from_spec(spec)
loader = spec.loader
- if loader is None:
+ if not isinstance(loader, importlib.abc.Loader):
return None
- loader.exec_module(handler) # type: ignore # FIXME: typeshed issue?
- return handler.handle # type: ignore
+ loader.exec_module(handler)
+ return getattr(handler, "handle")
except Exception as e:
print(e)
return None

MODIFY
zulip_bots/zulip_bots/finder.py
zulip_bots/zulip_bots/finder.py
import importlib
+import importlib.abc
import importlib.util
import os
from typing import Any, Optional, Text, Tuple
@@ -10,9 +11,9 @@ def import_module_from_source(path: Text, name: Text) -> Any:
spec = importlib.util.spec_from_file_location(name, path)
module = importlib.util.module_from_spec(spec)
loader = spec.loader
- if loader is None:
+ if not isinstance(loader, importlib.abc.Loader):
return None
- loader.exec_module(module) # type: ignore # FIXME: typeshed issue?
+ loader.exec_module(module)
return module
def import_module_by_name(name: Text) -> Any:

MODIFY
zulip_botserver/zulip_botserver/server.py
zulip_botserver/zulip_botserver/server.py
@@ -5,6 +5,7 @@ import logging
import json
import os
import sys
+import importlib.abc
import importlib.util
from collections import OrderedDict
@@ -102,9 +103,8 @@ def load_module_from_file(file_path: str) -> ModuleType:
# Wrapper around importutil; see https://stackoverflow.com/a/67692/3909240.
spec = importlib.util.spec_from_file_location("custom_bot_module", file_path)
lib_module = importlib.util.module_from_spec(spec)
- assert spec is not None
- assert spec.loader is not None
- spec.loader.exec_module(lib_module) # type: ignore # FIXME: typeshed issue?
+ assert isinstance(spec.loader, importlib.abc.Loader)
+ spec.loader.exec_module(lib_module)
return lib_module
def load_lib_modules(available_bots: List[str]) -> Dict[str, Any]:

mypy: Fix exec_module type: ignore comments.

Signed-off-by: Anders Kaseorg <anders@zulip.com>