refactor: add guard clause for readability

Both functions only execute based on a condition. In such cases
condition should immediately exit the function, this is called "guard
clause" and helps in readability (less indent, and easy to "exit" when
reading the code.
This commit is contained in:
Ankush Menat
2021-05-22 23:15:32 +05:30
parent 4b484d741d
commit c229ac9322

View File

@@ -359,7 +359,9 @@ class Item(WebsiteGenerator):
context.update(get_slideshow(self)) context.update(get_slideshow(self))
def set_attribute_context(self, context): def set_attribute_context(self, context):
if self.has_variants: if not self.has_variants:
return
attribute_values_available = {} attribute_values_available = {}
context.attribute_values = {} context.attribute_values = {}
context.selected_attributes = {} context.selected_attributes = {}
@@ -736,7 +738,9 @@ class Item(WebsiteGenerator):
def update_template_item(self): def update_template_item(self):
"""Set Show in Website for Template Item if True for its Variant""" """Set Show in Website for Template Item if True for its Variant"""
if self.variant_of: if not self.variant_of:
return
if self.show_in_website: if self.show_in_website:
self.show_variant_in_website = 1 self.show_variant_in_website = 1
self.show_in_website = 0 self.show_in_website = 0