lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
430 stars 52 forks source link

Add a way to ignore a field, without having to set `init=False` #20

Closed lebrice closed 3 years ago

lebrice commented 4 years ago

Is your feature request related to a problem? Please describe. Would be nice to have a way to tell SimpleParsing to simply ignore a field, (i.e., to not try to parse it via command-line.)

Describe the solution you'd like Something simple, elegant, and easy to implement.

Describe alternatives you've considered

Additional context This would be very helpful when trying to save/load state to files, for example. Your dataclass might have some command-line arguments as well as some attributes that are used to keep some kind of state. If field(init=False) is used, then the dataclasses.asdict(...) function doesn't return those fields, and they can't be passed to the constructor when creating them from a dictionary (read from a JSON file, for example)

lebrice commented 3 years ago

Fixed, you can pass cmd=False to field() and it will not add any arguments.