add module name collision check to before import and hooks

This commit is contained in:
jesopo 2020-01-28 10:20:52 +00:00
parent 7241027ff7
commit 499a03a0ad

View file

@ -217,6 +217,10 @@ class ModuleManager(object):
def _load_module(self, bot: "IRCBot.Bot", definition: ModuleDefinition, def _load_module(self, bot: "IRCBot.Bot", definition: ModuleDefinition,
check_dependency: bool=True) -> LoadedModule: check_dependency: bool=True) -> LoadedModule:
if definition.name in self.modules:
raise ModuleNameCollisionException("Module name '%s' "
"attempted to be used twice" % definition.name)
if check_dependency: if check_dependency:
dependencies = definition.get_dependencies() dependencies = definition.get_dependencies()
for dependency in dependencies: for dependency in dependencies:
@ -270,10 +274,6 @@ class ModuleManager(object):
for key, value in magic.get_exports(): for key, value in magic.get_exports():
context_exports.add(key, value) context_exports.add(key, value)
if definition.name in self.modules:
raise ModuleNameCollisionException("Module name '%s' "
"attempted to be used twice" % definition.name)
return LoadedModule(definition.name, module_title, module_object, return LoadedModule(definition.name, module_title, module_object,
context, import_name) context, import_name)