import the base class and check whether this obj has the required base class.

Signed-off-by: 夏恺(Xia Kai) <xiaket@gmail.com>
pull/14976/head
夏恺(Xia Kai) 9 years ago
parent cd6d865e27
commit 38092dcc27

@ -329,8 +329,13 @@ class PluginLoader:
obj = getattr(self._module_cache[path], self.class_name) obj = getattr(self._module_cache[path], self.class_name)
else: else:
obj = getattr(self._module_cache[path], self.class_name)(*args, **kwargs) obj = getattr(self._module_cache[path], self.class_name)(*args, **kwargs)
if self.base_class and self.base_class not in [base.__name__ for base in obj.__class__.__mro__]: if self.base_class:
return None # The import path is hardcoded and should be the right place,
# so we are not expecting an ImportError.
module = __import__(self.package, fromlist=[self.base_class])
# Check whether this obj has the required base class.
if not issubclass(obj.__class__, getattr(module, self.base_class, None)):
return None
return obj return obj

Loading…
Cancel
Save