Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daniel sandbox #62

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

Daniel sandbox #62

wants to merge 19 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Oct 24, 2020

#TODO: check if value can be imported.

lira/parsers/rst.py Outdated Show resolved Hide resolved
def is_importable(value):
module_name, class_name = value.rsplit(".",1)
MyClass = getattr(importlib.import_module(module_name), class_name, ValueError)
if MyClass is ValueError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check for validator_class is not None and isinstance(validator_class, Validator)

return value
def is_importable(value):
module_name, class_name = value.rsplit(".",1)
MyClass = getattr(importlib.import_module(module_name), class_name, ValueError)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to try...except in case there is an import error.

Co-authored-by: Santos Gallegos <[email protected]>
@stsewd
Copy link
Member

stsewd commented Oct 25, 2020

You can take some inspiration from

lira/lira/app.py

Lines 72 to 77 in df8ee50

package = importlib.import_module(book_path)
path = Path(package.__file__).parent
books_list.append(Book(root=path))
except ModuleNotFoundError:
log.warning("Unable to find book: %s", book_path)
except Exception as e:

Comment on lines 32 to 33
MyClass = getattr(importlib.import_module(module_name), class_name, None)
instance = MyClass()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to create an instance (I think), we just need to check if the class is a subclass of lira.validators.Validator

MyClass = getattr(importlib.import_module(module_name), class_name, None)
if MyClass is None or not issubclass(MyClass, Validator):
raise ValueError
else:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else can be removed

def is_importable(value):
module_name, class_name = value.rsplit(".", 1)
try:
MyClass = getattr(importlib.import_module(module_name), class_name, None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should name this TargetClass or something like that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants