I want to be able to convert a given object back into a YAML using hz.just but it fails. Or rather OmegaConf fails because the objects which hz.just creates are not the same as what the type hints expect. So the following snippet
import hydra_zen as hz
from dataclasses import dataclass
@dataclass
class Inner:
x: int = 0
@dataclass
class Outer:
outer: dict[str, Inner]
#outer: Inner
x = Outer(outer={'a': Inner(x=1)})
#x = Outer(outer=Inner(x=1))
cfg = hz.just(x)
print(hz.to_yaml(cfg))
fails with
ValidationError: Invalid type assigned: Builds_Inner is not a subclass of Inner. value: <class 'types.Builds_Inner'>
full_key: a
object_type=None
If I change (swap in commented lines) to Inner instead of dict of Inner values it works. So it is not entirely impossible... But my use-case has dict and it feels like this should work. A workaround is to abandon the type-hint for Inner and use Any. But I would like to keep the stricter hints: it will be too intrusive on the code-base and not very pythonic either.
hydra-zen is full wonderful surprises so maybe i am missing something :-)
I want to be able to convert a given object back into a YAML using
hz.justbut it fails. Or ratherOmegaConffails because the objects whichhz.justcreates are not the same as what the type hints expect. So the following snippetfails with
If I change (swap in commented lines) to
Innerinstead ofdictofInnervalues it works. So it is not entirely impossible... But my use-case hasdictand it feels like this should work. A workaround is to abandon the type-hint forInnerand useAny.But I would like to keep the stricter hints: it will be too intrusive on the code-base and not very pythonic either.hydra-zen is full wonderful surprises so maybe i am missing something :-)