Repository: omry/omegaconf

Issue:
consider implementing + operator for ListConfig

Discussion:

Patch:
diff --git a/omegaconf/listconfig.py b/omegaconf/listconfig.py
index 6969aab..d2696b5 100644
--- a/omegaconf/listconfig.py
+++ b/omegaconf/listconfig.py
@@ -207,3 +207,10 @@ class ListConfig(Config):
                 return v
 
         return MyItems(self.content)
+
+    def __add__(self, o):
+        # res is sharing this list's parent to allow interpolation to work as expected
+        res = ListConfig(parent=self.__dict__["parent"], content=[])
+        res.extend(self)
+        res.extend(o)
+        return res


Test patch:
diff --git a/tests/test_basic_ops_list.py b/tests/test_basic_ops_list.py
index a97aecb..d2e5a86 100644
--- a/tests/test_basic_ops_list.py
+++ b/tests/test_basic_ops_list.py
@@ -373,3 +373,27 @@ def test_hash():
     assert hash(c1) == hash(c2)
     c2[0] = 20
     assert hash(c1) != hash(c2)
+
+
+@pytest.mark.parametrize(
+    "list1, list2, expected",
+    [
+        ([], [], []),
+        ([1, 2], [3, 4], [1, 2, 3, 4]),
+        (["x", 2, "${0}"], [5, 6, 7], ["x", 2, "x", 5, 6, 7]),
+    ],
+)
+class TestListAdd:
+    def test_list_plus(self, list1, list2, expected):
+        list1 = OmegaConf.create(list1)
+        list2 = OmegaConf.create(list2)
+        expected = OmegaConf.create(expected)
+        ret = list1 + list2
+        assert ret == expected
+
+    def test_list_plus_eq(self, list1, list2, expected):
+        list1 = OmegaConf.create(list1)
+        list2 = OmegaConf.create(list2)
+        expected = OmegaConf.create(expected)
+        list1 += list2
+        assert list1 == expected