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

Updated ListConfig.append to use _set_item_impl #740

Merged
merged 2 commits into from
Jun 4, 2021
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: 1 addition & 1 deletion news/601.bugfix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ListConfig append now copies input config nodes
`ListConfig.append()` now copies input config nodes
23 changes: 5 additions & 18 deletions omegaconf/listconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,26 +246,13 @@ def __setitem__(self, index: Union[int, slice], value: Any) -> None:
self._format_and_raise(key=index, value=value, cause=e)

def append(self, item: Any) -> None:
content = self.__dict__["_content"]
index = len(content)
content.append(None)
try:
from omegaconf.omegaconf import _maybe_wrap

index = len(self)
self._validate_set(key=index, value=item)

if isinstance(item, Node):
do_deepcopy = not self._get_flag("no_deepcopy_set_nodes")
if do_deepcopy:
item = copy.deepcopy(item)

node = _maybe_wrap(
ref_type=self.__dict__["_metadata"].element_type,
key=index,
value=item,
is_optional=_is_optional(item),
parent=self,
)
self.__dict__["_content"].append(node)
self._set_item_impl(index, item)
except Exception as e:
del content[index]
self._format_and_raise(key=index, value=item, cause=e)
assert False

Expand Down