Skip to content

Intruction of merge flag to OmegaConf.update() #367

@omry

Description

@omry

OmegaConf.update() behavior when the input value was a list or a dictionary was to assign the value instead of to merge it:

cfg = OmegaConf.create({"a": {"b": 10}})
OmegaConf.update(cfg, "a", {"c": 20}})
# cfg is now {"a": {"c": 20}}

The intended behavior for update lines up better with a merge:

OmegaConf.update(cfg, "a", {"c": 20}})
# cfg is now {"a": {"b": 10, "c": 20}}

To support both use cases, a new merge flag is introduced to update:

def update(
    cfg: Container, key: str, value: Any = None, merge: Optional[bool] = None
) -> None:
  • None: issue a warning, default to False to maintain compatibility.
  • True : Merge config
  • False: Assign config

The default value for merge will become True in a future version.
To avoid unexpected behavior changes, please call update with merge=[True|False].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions