Closed tungalbert99 closed 10 months ago
Wondering if this is a pydantic specific thing 🤔 since it seems to work in an example https://brentyi.github.io/tyro/examples/02_nesting/04_nesting_in_containers/
Yes sorry for the trouble here, I think this is the same issue as #107!
One thing I'm still noticing is that the list of nested models is a little wonky. I'm not able to add a second FlaskConfig in the specification?
Sorry yeah, that seems like expected behavior -- unfortunately we don't currently support appending to dynamically-sized lists of structures like this.
If you have a field like flasks: list[FlaskConfig] = [FlaskConfig(...), FlaskConfig(...), FlaskConfig(...)]
, tyro
will currently let you override values in each FlaskConfig
object, but we don't have the ability to remove elements from the list or append new ones.
I imagine this is what you're seeing, where you have a length-1 default list and all tyro
lets you do is override values in this list. A similar behavior also shows up in the color_tuple_alt: tuple[Color, ...]
field in this nesting example.
Adding more functionality here is probably doable with a nontrivial amount of thought, in the meantime some workarounds I think are unideal but could work are:
id: int
becomes ids: list[int]
)FlaskConfig
with a tuple, like this should work because source_flasks
gets collapsed to a single argument:
FlaskConfig = tuple[str, SourceFlaskSize, int, int | None]
class Config(pydantic.BaseModel): source_flasks: list[FlaskConfig]
I like the tuple idea thank you!
I'm trying to provide defaults of nested pydantic models but the defaults don't show up and are requested as "required".
Steps for reproduction:
It's hard to tell if the min_length/max_length requirements work with tyro but in any case the error is that the default
FlaskConfig
is provided in pydantic but tyro seems to think it's not.