diff --git a/src/linkahead/common/models.py b/src/linkahead/common/models.py index 9644485a21ee26d393644497171062708bcb858d..a2aeb440c40d08dbb92727951908a476379d60c7 100644 --- a/src/linkahead/common/models.py +++ b/src/linkahead/common/models.py @@ -3002,9 +3002,10 @@ class Container(list): return xml2str(self.to_xml()) def __getitem__(self, key): - # Construct new Container from list slice + self_as_list_slice = super().__getitem__(key) if isinstance(self_as_list_slice, list): + # Construct new Container from list slice return Container().extend(self_as_list_slice) else: return self_as_list_slice diff --git a/unittests/test_container.py b/unittests/test_container.py index cfada7cc2d2fd21e8bbc4fb06c6e32e9346d87f8..6e0f096ead50ad06b90fc0291ff2d45f73435d58 100644 --- a/unittests/test_container.py +++ b/unittests/test_container.py @@ -192,3 +192,9 @@ def test_container_slicing(): f"element in slice was not Record, but {type(element)}" assert len(container_slice) == 2 assert cont[-1].name == "TestRec5" + + with pytest.raises(TypeError): + cont["stringkey"] + + with pytest.raises(TypeError): + cont[[0,2,3]]