Use getattr
to get Module
classes out of modules in ModuleManager.py; this
makes more sense and removes some errors from type linting
This commit is contained in:
parent
50ced296d1
commit
9466f57efc
1 changed files with 5 additions and 4 deletions
|
@ -89,10 +89,11 @@ class ModuleManager(object):
|
|||
|
||||
module = imp.load_source(self._import_name(name), path)
|
||||
|
||||
if not hasattr(module, "Module"):
|
||||
module_object_pointer = getattr(module, "Module", None)
|
||||
if not module_object_pointer:
|
||||
raise ModuleLoadException("module '%s' doesn't have a "
|
||||
"'Module' class." % name)
|
||||
if not inspect.isclass(module.Module):
|
||||
if not inspect.isclass(module_object_pointer):
|
||||
raise ModuleLoadException("module '%s' has a 'Module' attribute "
|
||||
"but it is not a class." % name)
|
||||
|
||||
|
@ -100,8 +101,8 @@ class ModuleManager(object):
|
|||
context_events = self.events.new_context(context)
|
||||
context_exports = self.exports.new_context(context)
|
||||
context_timers = self.timers.new_context(context)
|
||||
module_object = module.Module(bot, context_events, context_exports,
|
||||
context_timers, self.log)
|
||||
module_object = module_object_pointer(bot, context_events,
|
||||
context_exports, context_timers, self.log)
|
||||
|
||||
if not hasattr(module_object, "_name"):
|
||||
module_object._name = name.title()
|
||||
|
|
Loading…
Reference in a new issue