dfurtado / dataclass-csv

Map CSV to Data Classes
Other
194 stars 21 forks source link

Support Optional fields #23

Closed johnthagen closed 4 years ago

johnthagen commented 4 years ago

It would be useful if, rather than having to add a default (potentially meaningless) value to a field, instead you could mark it as Optional.

from dataclasses import dataclass
from typing import Optional

@dataclass
class User:
    firstname: str
    email: Optional[str]
    age: int

If the field is not provided in the row, the field is set to None. This will allow for a type-safe way to detect and handle missing values.

dfurtado commented 4 years ago

This feature has been already implemented. Closing it.