SimpleParsing icon indicating copy to clipboard operation
SimpleParsing copied to clipboard

Idea: Refactoring of the `FieldWrapper` class

Open lebrice opened this issue 3 years ago • 1 comments

Would be a good idea to refactor the FieldWrapper class a bit. The args_dict (a dict of all the argparse arguments for a given field, that get passed to parser.add_arguments in the FieldWrapper) is currently created using a mix of three things (with increasing priority):

  • The type annotation of the field
  • The dataclass context (e.g. when adding an Optional[Dataclass] field on another dataclass, or when using the default or prefix arguments to parser.add_arguments, etc.
  • The manual overrides (arguments of parser.add_argument passed to the field function)

These three are currently a bit mixed together in the FieldWrapper class. It would perhaps be preferable to have them be cleanly separated.

lebrice avatar Jun 22 '22 18:06 lebrice

Yeah, it needs some love. I find it especially limiting that DataclassWrapper/FieldWrapper do too much by themselves and so injecting new information into the process is hard (e.g. creating a feature that has an effect at the field level but is specified as an argument to add_arguments())

idoby avatar Aug 20 '22 17:08 idoby