-
Notifications
You must be signed in to change notification settings - Fork 0
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
Ignored attributes added in robula model #196
Ignored attributes added in robula model #196
Conversation
utils/robula.py
Outdated
if config["ignored_attributes"] is not None and len(config["ignored_attributes"]) != 0: | ||
self.attribute_black_list.extend(config["ignored_attributes"]) | ||
self.attribute_black_list = list(dict.fromkeys(self.attribute_black_list)) |
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.
Could be just
if config["ignored_attributes"] is not None and len(config["ignored_attributes"]) != 0: | |
self.attribute_black_list.extend(config["ignored_attributes"]) | |
self.attribute_black_list = list(dict.fromkeys(self.attribute_black_list)) | |
if config.ignored_attributes: | |
self.attribute_black_list.extend(config.ignored_attributes) |
Pydantic guarantees us that ignored_attributes
is either None, either list and bool([]) is False
so it doesn't make sense to check the length here.
And this line changes nothing
self.attribute_black_list = list(dict.fromkeys(self.attribute_black_list))
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.
self.attribute_black_list = list(dict.fromkeys(self.attribute_black_list))
With this line I wanted to make sure that there are no duplicates when we extend the list.
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.
In such cases it's better to leave comment explaining this, because as you can see, it was really not obvious :)
Can we convert self.attribute_black_list
to set to avoid having duplicates there?
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.
Yes, we can do it with the set too. But in this way we will keep the order of the elements. I will add a comment.
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.
But in this way we will keep the order of the elements
Does it matter?
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.
Well in this case it actually doesn't :)
utils/robula.py
Outdated
if config.ignored_attributes: | ||
self.attribute_black_list.extend(config.ignored_attributes) | ||
# Remove duplicates from the list | ||
self.attribute_black_list = list(set(self.attribute_black_list)) |
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.
What I actually meant was
class RobulaPlus:
def __init__(self, element, document, config):
...
self.attribute_black_list = {
"href",
"jdn-hash",
...,
}
...
if config.ignored_attributes:
self.attribute_black_list.update(config.ignored_attributes)
It's much cleaner code and we do less work here. We don't even have to mention something about duplicates in this case.
utils/robula.py
Outdated
@@ -158,6 +158,9 @@ def __init__(self, element, document, config): | |||
self.element = element | |||
self.document = document | |||
|
|||
if config["ignored_attributes"] is not None and len(config["ignored_attributes"]) != 0: |
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.
Why not just
if config["ignored_attributes"] is not None and len(config["ignored_attributes"]) != 0: | |
if config["ignored_attributes"]: |
?
No description provided.