Skip to content

Commit 6d47795

Browse files
committed
Name and document some types
1 parent 59c8145 commit 6d47795

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

cvat/apps/engine/media_extractors.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ def __getitem__(self, idx: int):
243243

244244

245245
class IMediaReader(ABC):
246+
# In both of these tuples, the first element is either the path to the frame or its contents.
247+
# In ImageFrame, the second element is the path to the frame.
248+
ImageFrame: TypeAlias = tuple[str | io.BytesIO, str]
249+
VideoFrame: TypeAlias = tuple[av.VideoFrame, None]
250+
246251
def __init__(
247252
self,
248253
*,
@@ -262,7 +267,7 @@ def __init__(
262267
self._dimension = dimension
263268

264269
@abstractmethod
265-
def __iter__(self) -> Iterator[tuple[Any, str | None]]:
270+
def __iter__(self) -> Iterator[ImageFrame] | Iterator[VideoFrame]:
266271
pass
267272

268273
@abstractmethod
@@ -313,7 +318,7 @@ def __init__(
313318
self._source_paths = sort(source_paths, sorting_method)
314319
self._sorting_method = sorting_method
315320

316-
def __iter__(self):
321+
def __iter__(self) -> Iterator[IMediaReader.ImageFrame]:
317322
for i in self.frame_range:
318323
yield (self.get_image(i), self.get_path(i))
319324

@@ -611,7 +616,7 @@ def iterate_frames(
611616
self,
612617
*,
613618
frame_filter: bool | Iterable[int] = True,
614-
) -> Iterator[tuple[av.VideoFrame, None]]:
619+
) -> Iterator[IMediaReader.VideoFrame]:
615620
"""
616621
If provided, frame_filter must be an ordered sequence in the ascending order.
617622
'True' means using the frames configured in the reader object.
@@ -658,7 +663,7 @@ def iterate_frames(
658663
if next_frame_filter_frame is None:
659664
return
660665

661-
def __iter__(self) -> Iterator[tuple[av.VideoFrame, None]]:
666+
def __iter__(self) -> Iterator[IMediaReader.VideoFrame]:
662667
return self.iterate_frames()
663668

664669
def _read_av_container(self) -> av.container.InputContainer:

0 commit comments

Comments
 (0)