From 1aed1e935808927347936f80512e632f0a49c142 Mon Sep 17 00:00:00 2001 From: antoine-b-smartway Date: Wed, 24 Apr 2024 15:03:11 +0200 Subject: [PATCH] int-679 code review feedbacks --- magicparse/schema.py | 50 +++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/magicparse/schema.py b/magicparse/schema.py index 81a4bea..914d45c 100644 --- a/magicparse/schema.py +++ b/magicparse/schema.py @@ -73,30 +73,32 @@ def stream_parse( for row in reader: row_number += 1 - if any(row): - errors = [] - item = {} - for field in self.fields: - try: - value = field.read_value(row) - except Exception as exc: - errors.append({"row-number": row_number, **field.error(exc)}) - continue - - item[field.key] = value - - for computed_field in self.computed_fields: - try: - value = computed_field.read_value(item) - except Exception as exc: - errors.append( - {"row-number": row_number, **computed_field.error(exc)} - ) - continue - - item[computed_field.key] = value - - yield item, errors + if not any(row): + continue + + errors = [] + item = {} + for field in self.fields: + try: + value = field.read_value(row) + except Exception as exc: + errors.append({"row-number": row_number, **field.error(exc)}) + continue + + item[field.key] = value + + for computed_field in self.computed_fields: + try: + value = computed_field.read_value(item) + except Exception as exc: + errors.append( + {"row-number": row_number, **computed_field.error(exc)} + ) + continue + + item[computed_field.key] = value + + yield item, errors class CsvSchema(Schema):