This PR enables OmegaConf.to_container(..., throw_on_missing=False) to work for structured configs when structured_config_mode=SCMode.INSTANTIATE. Closes #1103.
In addition, this PR moves MISSING from omegaconf.py into base.py to avoid a circular import issue.
Here is an example of the behavior enabled by this PR:
# repro.py
from dataclasses import dataclass
from enum import Enum
import omegaconf
from omegaconf import OmegaConf
@dataclass(frozen=True)
class A:
x: int
a = OmegaConf.create(A)
container = OmegaConf.to_container(
a,
throw_on_missing=False,
structured_config_mode=omegaconf.SCMode.INSTANTIATE,
)
assert isinstance(container, A)
print(container)
BEFORE:
$ python repro.py
Traceback (most recent call last):
File "/home/homestar/dev/omegaconf/repro.py", line 12, in <module>
cfg = OmegaConf.to_container(
...
omegaconf.errors.MissingMandatoryValue: Structured config of type `A` has missing mandatory value: x
full_key: x
object_type=A
This PR enables
OmegaConf.to_container(..., throw_on_missing=False)
to work for structured configs whenstructured_config_mode=SCMode.INSTANTIATE
. Closes #1103.In addition, this PR moves
MISSING
fromomegaconf.py
intobase.py
to avoid a circular import issue.Here is an example of the behavior enabled by this PR:
BEFORE:
AFTER: