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:
parent
51b1136dce
commit
2c99e83d52
@ -118,10 +118,13 @@ def generate_bom(harness: "Harness") -> List[BOMEntry]:
|
|||||||
return [{**entry, 'id': index} for index, entry in enumerate(bom, 1)]
|
return [{**entry, 'id': index} for index, entry in enumerate(bom, 1)]
|
||||||
|
|
||||||
def get_bom_index(bom: List[BOMEntry], part: AdditionalComponent) -> int:
|
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
|
# 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}))
|
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]]:
|
def bom_list(bom: List[BOMEntry]) -> List[List[str]]:
|
||||||
"""Return list of BOM rows as lists of column strings with headings in top row."""
|
"""Return list of BOM rows as lists of column strings with headings in top row."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user