Skip to content

Commit

Permalink
Refactor entities/common
Browse files Browse the repository at this point in the history
Extract shadowing check from make_items_product_specific. It supposed
to lower the cognitive complexity of the function.
  • Loading branch information
evgenyz committed Nov 25, 2022
1 parent c0b411e commit 306f76e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ssg/entities/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
)


def item_is_shadowed(items_dict, label, value):
return label in items_dict and value != items_dict[label]


def make_items_product_specific(items_dict, product_suffix, allow_overwrites=False):
new_items = dict()
for full_label, value in items_dict.items():
Expand All @@ -43,7 +47,7 @@ def make_items_product_specific(items_dict, product_suffix, allow_overwrites=Fal
if not full_label.endswith(product_suffix):
continue

if label in items_dict and not allow_overwrites and value != items_dict[label]:
if not allow_overwrites and item_is_shadowed(items_dict, label, value):
msg = (
"There is a product-qualified '{item_q}' item, "
"but also an unqualified '{item_u}' item "
Expand Down

0 comments on commit 306f76e

Please sign in to comment.