Slightly cleaner usage of importlib, making sure we import the correct module

This commit is contained in:
Daniel Goldberg 2019-10-30 15:23:37 +02:00
parent 9c40b4a022
commit 37704e3eeb
1 changed files with 1 additions and 1 deletions

View File

@ -26,7 +26,7 @@ def get_instances(base_package_name, base_package_file, parent_class):
# Go through all of files # Go through all of files
for file in candidate_files: for file in candidate_files:
# Import module from that file # Import module from that file
module = importlib.import_module(base_package_name + '.' + file) module = importlib.import_module('.' + file, base_package_name)
# Get all classes in a module # Get all classes in a module
# m[1] because return object is (name,class) # m[1] because return object is (name,class)
classes = [m[1] for m in inspect.getmembers(module, inspect.isclass) classes = [m[1] for m in inspect.getmembers(module, inspect.isclass)