From 45b13ef79736c027f8fadfdd10661404908edeb9 Mon Sep 17 00:00:00 2001 From: KV Date: Sat, 14 Nov 2020 20:51:50 +0100 Subject: [PATCH] Use the same lambda in get_bom_index() as for deduplicating BOM Move the lambda declaration out of the function scope for common access from two different functions. --- src/wireviz/wv_bom.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index 84426a5..d9a1f25 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -36,6 +36,8 @@ def get_additional_component_bom(component: Union[Connector, Cable]) -> List[dic }) return(bom_entries) +bom_types_group = lambda bt: (bt['item'], bt['unit'], bt['manufacturer'], bt['mpn'], bt['pn']) + def generate_bom(harness): from wireviz.Harness import Harness # Local import to avoid circular imports bom_entries = [] @@ -97,7 +99,6 @@ def generate_bom(harness): # deduplicate bom bom = [] - bom_types_group = lambda bt: (bt['item'], bt['unit'], bt['manufacturer'], bt['mpn'], bt['pn']) for group in Counter([bom_types_group(v) for v in bom_entries]): group_entries = [v for v in bom_entries if bom_types_group(v) == group] designators = [] @@ -121,7 +122,7 @@ def get_bom_index(bom: List[dict], extra: AdditionalComponent) -> int: # Remove linebreaks and clean whitespace of values in search target = tuple(clean_whitespace(v) for v in (extra.description, extra.unit, extra.manufacturer, extra.mpn, extra.pn)) for entry in bom: - if (entry['item'], entry['unit'], entry['manufacturer'], entry['mpn'], entry['pn']) == target: + if bom_types_group(entry) == target: return entry['id'] return None