Skip to content

Commit 655f0d8

Browse files
committed
Name and document some types
1 parent 59c8145 commit 655f0d8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

cvat/apps/engine/media_extractors.py

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

244244

245245
class IMediaReader(ABC):
246+
ImageFrame: TypeAlias = tuple[str | io.BytesIO, str]
247+
"""
248+
The first element is the contents of the image or the file system path to it.
249+
The second element is always the path to the image.
250+
"""
251+
252+
VideoFrame: TypeAlias = tuple[av.VideoFrame, None]
253+
246254
def __init__(
247255
self,
248256
*,
@@ -262,7 +270,7 @@ def __init__(
262270
self._dimension = dimension
263271

264272
@abstractmethod
265-
def __iter__(self) -> Iterator[tuple[Any, str | None]]:
273+
def __iter__(self) -> Iterator[ImageFrame] | Iterator[VideoFrame]:
266274
pass
267275

268276
@abstractmethod
@@ -313,7 +321,7 @@ def __init__(
313321
self._source_paths = sort(source_paths, sorting_method)
314322
self._sorting_method = sorting_method
315323

316-
def __iter__(self):
324+
def __iter__(self) -> Iterator[IMediaReader.ImageFrame]:
317325
for i in self.frame_range:
318326
yield (self.get_image(i), self.get_path(i))
319327

@@ -611,7 +619,7 @@ def iterate_frames(
611619
self,
612620
*,
613621
frame_filter: bool | Iterable[int] = True,
614-
) -> Iterator[tuple[av.VideoFrame, None]]:
622+
) -> Iterator[IMediaReader.VideoFrame]:
615623
"""
616624
If provided, frame_filter must be an ordered sequence in the ascending order.
617625
'True' means using the frames configured in the reader object.
@@ -658,7 +666,7 @@ def iterate_frames(
658666
if next_frame_filter_frame is None:
659667
return
660668

661-
def __iter__(self) -> Iterator[tuple[av.VideoFrame, None]]:
669+
def __iter__(self) -> Iterator[IMediaReader.VideoFrame]:
662670
return self.iterate_frames()
663671

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

0 commit comments

Comments
 (0)