Skip to content

Commit

Permalink
BaseAnnotationList.clear() returns the contained annotations (#291)
Browse files Browse the repository at this point in the history
* BAseAnnotationList.clear() returns the contained annotations

* add documentation
  • Loading branch information
ArneBinder authored Jul 20, 2023
1 parent 6f35d1b commit 8ada461
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/pytorch_ie/core/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ada461

Please sign in to comment.