Skip to content

Commit

Permalink
Updated ListConfig.append to use _set_item_impl (#740)
Browse files Browse the repository at this point in the history
  • Loading branch information
omry authored Jun 4, 2021
1 parent 3cc1911 commit 6c732c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
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 @@ -247,26 +247,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

0 comments on commit 6c732c1

Please sign in to comment.