Revert "Use a generator expressions and raise exception if failing"

This reverts commit 96d393dfb757afc61ffb319c34035d8d2ce7c33d.
However, raising an exception if failing the BOM index search is still
wanted, so a custom exception is raised instead of returning None.
This commit is contained in:
KV 2021-03-25 20:09:22 +01:00
parent 51b1136dce
commit 2c99e83d52

View File

@ -118,10 +118,13 @@ def generate_bom(harness: "Harness") -> List[BOMEntry]:
return [{**entry, 'id': index} for index, entry in enumerate(bom, 1)]
def get_bom_index(bom: List[BOMEntry], part: AdditionalComponent) -> int:
"""Return id of BOM entry or raise StopIteration if not found."""
"""Return id of BOM entry or raise exception if not found."""
# Remove linebreaks and clean whitespace of values in search
target = tuple(clean_whitespace(v) for v in bom_types_group({**asdict(part), 'description': part.description}))
return next(entry['id'] for entry in bom if bom_types_group(entry) == target)
for entry in bom:
if bom_types_group(entry) == target:
return entry['id']
raise Exception('Internal error: No BOM entry found matching: ' + '|'.join(target))
def bom_list(bom: List[BOMEntry]) -> List[List[str]]:
"""Return list of BOM rows as lists of column strings with headings in top row."""