Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interpolation to structured config from within typed list #1139

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions omegaconf/listconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def _validate_set(self, key: Any, value: Any) -> None:
vk = get_value_kind(value)
if vk == ValueKind.MANDATORY_MISSING:
return
if vk == ValueKind.INTERPOLATION:
return
else:
is_optional, target_type = _resolve_optional(self._metadata.element_type)
value_type = OmegaConf.get_type(value)
Expand Down
2 changes: 2 additions & 0 deletions tests/structured_conf/data/attr_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class OptionalUser:
class InterpolationToUser:
user: User = User("Bond", 7)
admin: User = II("user")
admin_list: List[User] = [II("user")]
admin_dict: Dict[str, User] = {"bond": II("user")}


@attr.s(auto_attribs=True)
Expand Down
2 changes: 2 additions & 0 deletions tests/structured_conf/data/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class OptionalUser:
class InterpolationToUser:
user: User = field(default_factory=lambda: User("Bond", 7))
admin: User = II("user")
admin_list: List[User] = field(default_factory=lambda: [II("user")])
admin_dict: Dict[str, User] = field(default_factory=lambda: {"bond": II("user")})


@dataclass
Expand Down
2 changes: 2 additions & 0 deletions tests/structured_conf/data/dataclasses_pre_311.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class OptionalUser:
class InterpolationToUser:
user: User = User("Bond", 7)
admin: User = II("user")
admin_list: List[User] = field(default_factory=lambda: [II("user")])
admin_dict: Dict[str, User] = field(default_factory=lambda: {"bond": II("user")})


@dataclass
Expand Down
4 changes: 4 additions & 0 deletions tests/structured_conf/test_structured_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ def test_interpolation_to_structured(self, module: Any, resolve: bool) -> None:
OmegaConf.resolve(cfg)
assert OmegaConf.get_type(cfg.admin) is module.User
assert cfg.admin == {"name": "Bond", "age": 7}
assert OmegaConf.get_type(cfg.admin_list[0]) is module.User
assert cfg.admin_list == [{"name": "Bond", "age": 7}]
assert OmegaConf.get_type(cfg.admin_dict["bond"]) is module.User
assert cfg.admin_dict == {"bond": {"name": "Bond", "age": 7}}

class TestMissing:
def test_missing1(self, module: Any) -> None:
Expand Down