lebrice / SimpleParsing

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

default values passed to `mutable_field` aren't used properly #77

Closed lebrice closed 1 year ago

lebrice commented 3 years ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce

from simple_parsing import ArgumentParser
from dataclasses import dataclass
from simple_parsing.helpers import mutable_field

@dataclass
class Foo:
    bar: int = 123

@dataclass
class Baz:
    a_foo: Foo = mutable_field(Foo, bar=111)
    b_foo: Foo = mutable_field(Foo, bar=222)

if __name__ == "__main__":
    parser = ArgumentParser()
    parser.add_arguments(Baz, "baz")
    args = parser.parse_args()
    a_foo: Foo = args.baz.a_foo
    b_foo: Foo = args.baz.b_foo
    print(a_foo.bar, b_foo.bar)

Expected behavior A clear and concise description of what you expected to happen.

$ python issue.py
111 222

Actual behavior A clear and concise description of what is happening.

$ python issue.py
123 123
ryanai3 commented 1 year ago

@lebrice I'm running into this as well - is there a fix, or recommended workaround?

lebrice commented 1 year ago

Hey there @ryanai3 , I've just added a new test in this branch here, and It seems the issue was fixed: https://github.com/lebrice/SimpleParsing/pull/218

Would you mind sharing a code snippet or describing a bit more the kind of context you're having this error in?

Thanks!