ProtixIT / dataclass-binder

Python library to bind TOML data to dataclasses in a type-safe way
MIT License
13 stars 2 forks source link

Ignore dataclass fields with init=False #2

Closed mthuurne closed 1 year ago

mthuurne commented 1 year ago

See this TODO comment:

https://github.com/ProtixIT/dataclass-binder/blob/8e747018517dddfa91bdf4c3413126759779fbba/src/dataclass_binder/_impl.py#L2

It is possible for a dataclass field to define init=False, which means that field cannot be initialized via the __init__() method. This is a problem for the binder, as it passes all parsed fields to __init__().

The use case for init=False offered by the standard library documentation is to mark fields initialized via __post_init__(). This use case would be satisfied by simply having the binder ignore all fields with init=False.