Skip to content

Commit

Permalink
int-679 code review feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine-b-smartway committed Apr 24, 2024
1 parent da4d895 commit 1aed1e9
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions magicparse/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 1aed1e9

Please sign in to comment.