lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
401 stars 50 forks source link

Default dict arguments (with partial defaults) #84

Closed idoby closed 2 years ago

idoby commented 2 years ago

Add ability to pass a dictionary as the default value for a dataclass argument, with support for only some fields being provided a default value.

idoby commented 2 years ago

Hi @lebrice, I'm building an experiment automation library for ML and I'm using your library to pull args from the command line in a typesafe way. Great library, just missing a couple of things, which I want to add.

Thanks

idoby commented 2 years ago

Hi, my project is not open source yet, it's too fresh for that yet. The first thing I want to add is the ability to parse polymorphic data classes from the command line, but this will be tricky...

lebrice commented 2 years ago

Merging this now, thanks for your contribution!

Just out of curiosity, what do you mean by "parse polymorphic data classes"?

idoby commented 2 years ago

Thanks for the merge, mate!

I mean getting something like this from the command line in a typesafe way:

@dataclass 
class Base:
    num1: int = 5

@dataclass
class Derived1(Base):
    num_specific_to_this_class: float = 7.5

class Derived2(Base):
    ...
lebrice commented 2 years ago

This isn't hard at all though! It's already supported with Simple-Parsing. Depending on what you want to do, subparsers might be the best way to go about this. Let me know if you have any issues with this.

idoby commented 1 year ago

Hi @lebrice It seems like both features I added (this and #124) got marked as deprecated. Do you intend to remove them? Why? In that case, I will need to find an alternative to SP or fork it.

lebrice commented 1 year ago

Hey @idoby , If I'm being honest, I don't remember why exactly I marked those as deprecated. I'm not thinking of removing them anytime soon.

Feel free to fork the repo if you want, but I don't intend to remove those without good reason.