mypy: Fix exec_module type: ignore comments.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
f2e2f1c7ff
commit
19f5b4f6a6
3 changed files with 10 additions and 8 deletions
|
@ -3,6 +3,7 @@
|
|||
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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue