Open mmcdermott opened 4 years ago
This can be solved using dataclasses.make_dataclass
(ctrl+f
make_dataclass
)
This takes a class name, list of fields, and some other arguments, and returns a dataclass object.
Relatedly, the post init processing options allow for bubbling validation up to the top level base class.
There is now a default argparse inference function based just on the dataclass spec. The interface is clunky, though, in particular for help messages and the output dir arg name. Some further unification (e.g., a config file that defines the spec, and is then read into a class programmatically) would be best, as it would decouple this from the dataclass metadata information (even if that was how everything was ultimately stored).
Currently, the user has to pass the arg spec twice, once in the dataclass definition, and another time in the argparse spec. This should be avoided - the spec should be defined only once, then argparse spec should be built automatically. This would also open up extensibility to other argparse system (e.g., abseil, click,
--docopt
). Additionally, this means that args set via class instantiation directly (e.g., in a Jupyter Notebook) lack validation. Validation should be decentralized from the argparse utility and instead done via the main class (or both).