From 6c732c1cef0d5dec534f07f7806f3b77f8a9e151 Mon Sep 17 00:00:00 2001 From: Omry Yadan Date: Thu, 3 Jun 2021 17:04:10 -0700 Subject: [PATCH] Updated ListConfig.append to use _set_item_impl (#740) --- news/601.bugfix | 2 +- omegaconf/listconfig.py | 23 +++++------------------ 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/news/601.bugfix b/news/601.bugfix index 5b583ebd2..71ddcaf9b 100644 --- a/news/601.bugfix +++ b/news/601.bugfix @@ -1 +1 @@ -ListConfig append now copies input config nodes +`ListConfig.append()` now copies input config nodes diff --git a/omegaconf/listconfig.py b/omegaconf/listconfig.py index 08a7d4e38..555e949a1 100644 --- a/omegaconf/listconfig.py +++ b/omegaconf/listconfig.py @@ -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