diff --git a/src/pytorch_ie/core/document.py b/src/pytorch_ie/core/document.py index a088dc72..4c61a416 100644 --- a/src/pytorch_ie/core/document.py +++ b/src/pytorch_ie/core/document.py @@ -336,12 +336,17 @@ def extend(self, annotations: Iterable[T]) -> None: def __repr__(self) -> str: return f"BaseAnnotationList({str(self._annotations)})" - def clear(self): + def clear(self) -> List[T]: + """ + Detach all annotations from the layer and return them. + """ + result = list(self._annotations) for annotation in self._annotations: annotation.set_targets(None) self._annotations = [] + return result - def pop(self, index: int = -1): + def pop(self, index: int = -1) -> T: ann = self._annotations.pop(index) ann.set_targets(None) return ann