From 8ada46152121d0a7ca67446f75fa0805fd8d5317 Mon Sep 17 00:00:00 2001 From: ArneBinder Date: Thu, 20 Jul 2023 14:03:05 +0200 Subject: [PATCH] BaseAnnotationList.clear() returns the contained annotations (#291) * BAseAnnotationList.clear() returns the contained annotations * add documentation --- src/pytorch_ie/core/document.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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