-
Notifications
You must be signed in to change notification settings - Fork 19
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
base: master
Are you sure you want to change the base?
Daniel sandbox #62
Conversation
lira/parsers/rst.py
Outdated
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: |
There was a problem hiding this comment.
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)
lira/parsers/rst.py
Outdated
return value | ||
def is_importable(value): | ||
module_name, class_name = value.rsplit(".",1) | ||
MyClass = getattr(importlib.import_module(module_name), class_name, ValueError) |
There was a problem hiding this comment.
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]>
You can take some inspiration from Lines 72 to 77 in df8ee50
|
lira/parsers/rst.py
Outdated
MyClass = getattr(importlib.import_module(module_name), class_name, None) | ||
instance = MyClass() |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
lira/parsers/rst.py
Outdated
def is_importable(value): | ||
module_name, class_name = value.rsplit(".", 1) | ||
try: | ||
MyClass = getattr(importlib.import_module(module_name), class_name, None) |
There was a problem hiding this comment.
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
#TODO: check if value can be imported.