argparse_dataclass icon indicating copy to clipboard operation
argparse_dataclass copied to clipboard

Is nested dataclass supported?

Open sleepwalker2017 opened this issue 3 years ago • 3 comments
trafficstars

from argparse_dataclass import dataclass
from argparse_dataclass import ArgumentParser

@dataclass
class SubOption:
    a: int = 1
    b: int = 2

@dataclass
class Options:
    x: int = 42
    y: bool = False
    sub: SubOption = None

parser = ArgumentParser(Options)
x = parser.parse_args(['--sub', '1'])
print(x)

for example, how can I parse args to get a value for sub?

sleepwalker2017 avatar Sep 28 '22 02:09 sleepwalker2017

This example doesn't make much sense to me. What attribute of SubOption should be getting set to 1?

mivade avatar Sep 28 '22 14:09 mivade

This example doesn't make much sense to me. What attribute of SubOption should be getting set to 1?

I mean, if I have a nested dataclass for example Options, how can I set the values in SubOptions.

python test.py --sub.a 2 --sub.b 1 Seems this usage is not supported. How can I set the value of sub.a?

sleepwalker2017 avatar Oct 11 '22 10:10 sleepwalker2017

This example doesn't make much sense to me. What attribute of SubOption should be getting set to 1?

Let me say it more clearly, in the following example, how can I set 'logging' to False? image

sleepwalker2017 avatar Oct 11 '22 10:10 sleepwalker2017