Closed mainrs closed 3 months ago
Hi @mainrs!
Here are some runnable options for getting --seed INT
and --flag1 INT
. Do any of them help?
(1) Standard dataclass inheritance might be the easiest:
from dataclasses import dataclass
import tyro
@dataclass
class CommonConfig:
seed: int = 0
@dataclass
class CustomConfig(CommonConfig):
flag1: int = 1
tyro.cli(CustomConfig)
(2) tyro.conf.OmitArgPrefixes
will flatten all of the arguments:
from dataclasses import dataclass
import tyro
@dataclass
class CommonConfig:
seed: int = 0
@dataclass
class CustomConfig:
common: CommonConfig
flag1: int = 1
tyro.cli(tyro.conf.OmitArgPrefixes[CustomConfig])
(3) You can "erase" the name of the common
field, which will remove the common.
prefix. This is the most cryptic option (and frankly not well-documented), but it's in the tyro
tests:
from dataclasses import dataclass
import tyro
from typing import Annotated
@dataclass
class CommonConfig:
seed: int = 0
@dataclass
class CustomConfig:
common: Annotated[CommonConfig, tyro.conf.arg(name="")]
flag1: int = 1
tyro.cli(CustomConfig)
I didn't think about inheritance, sorry! Thanks for helping me out!
Basically I have a dataclass that contains arguments that all my script files should support. Is it somehow possible to tell
tyro
that I want to include all the fields of a dataclass as if I defined them inside the current dataclass? Basically, flattening.Now, calling
python script1.py --seed 1
that holdscli1
should work as well aspython script2.py --seed 2
. The first prints one as the seed, the second 2.