Skip to content

Commit 1d6dc86

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

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

cvat/apps/engine/media_extractors.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,12 @@ def __getitem__(self, idx: int):
241241

242242
return value
243243

244-
245244
class IMediaReader(ABC):
245+
# In both of these tuples, the first element is either the path to the frame or its contents.
246+
# In ImageFrame, the second element is the path to the frame.
247+
ImageFrame: TypeAlias = tuple[str | io.BytesIO, str]
248+
VideoFrame: TypeAlias = tuple[av.VideoFrame, None]
249+
246250
def __init__(
247251
self,
248252
*,
@@ -262,7 +266,7 @@ def __init__(
262266
self._dimension = dimension
263267

264268
@abstractmethod
265-
def __iter__(self) -> Iterator[tuple[Any, str | None]]:
269+
def __iter__(self) -> Iterator[ImageFrame] | Iterator[VideoFrame]:
266270
pass
267271

268272
@abstractmethod
@@ -313,7 +317,7 @@ def __init__(
313317
self._source_paths = sort(source_paths, sorting_method)
314318
self._sorting_method = sorting_method
315319

316-
def __iter__(self):
320+
def __iter__(self) -> Iterator[IMediaReader.ImageFrame]:
317321
for i in self.frame_range:
318322
yield (self.get_image(i), self.get_path(i))
319323

@@ -611,7 +615,7 @@ def iterate_frames(
611615
self,
612616
*,
613617
frame_filter: bool | Iterable[int] = True,
614-
) -> Iterator[tuple[av.VideoFrame, None]]:
618+
) -> Iterator[IMediaReader.VideoFrame]:
615619
"""
616620
If provided, frame_filter must be an ordered sequence in the ascending order.
617621
'True' means using the frames configured in the reader object.
@@ -658,7 +662,7 @@ def iterate_frames(
658662
if next_frame_filter_frame is None:
659663
return
660664

661-
def __iter__(self) -> Iterator[tuple[av.VideoFrame, None]]:
665+
def __iter__(self) -> Iterator[IMediaReader.VideoFrame]:
662666
return self.iterate_frames()
663667

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

0 commit comments

Comments
 (0)