Skip to content

Commit c8b6acf

Browse files
maksdamirDamir Maksyutov
andauthored
Correct seek signature to return int instead of bytes (#838)
Co-authored-by: Damir Maksyutov <[email protected]>
1 parent b141814 commit c8b6acf

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

examples/decoding/file_like.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def read(self, size: int) -> bytes:
215215
self.num_reads += 1
216216
return self._file.read(size)
217217

218-
def seek(self, offset: int, whence: int) -> bytes:
218+
def seek(self, offset: int, whence: int) -> int:
219219
self.num_seeks += 1
220220
return self._file.seek(offset, whence)
221221

src/torchcodec/decoders/_audio_decoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AudioDecoder:
3535
- If ``bytes`` object or ``torch.Tensor``: the raw encoded audio data.
3636
- If file-like object: we read video data from the object on demand. The object must
3737
expose the methods `read(self, size: int) -> bytes` and
38-
`seek(self, offset: int, whence: int) -> bytes`. Read more in:
38+
`seek(self, offset: int, whence: int) -> int`. Read more in:
3939
:ref:`sphx_glr_generated_examples_decoding_file_like.py`.
4040
stream_index (int, optional): Specifies which stream in the file to decode samples from.
4141
Note that this index is absolute across all media types. If left unspecified, then

src/torchcodec/decoders/_decoder_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ def create_decoder(
4848
f"Unknown source type: {type(source)}. "
4949
"Supported types are str, Path, bytes, Tensor and file-like objects with "
5050
"read(self, size: int) -> bytes and "
51-
"seek(self, offset: int, whence: int) -> bytes methods."
51+
"seek(self, offset: int, whence: int) -> int methods."
5252
)

src/torchcodec/decoders/_video_decoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class VideoDecoder:
3030
- If ``bytes`` object or ``torch.Tensor``: the raw encoded video data.
3131
- If file-like object: we read video data from the object on demand. The object must
3232
expose the methods `read(self, size: int) -> bytes` and
33-
`seek(self, offset: int, whence: int) -> bytes`. Read more in:
33+
`seek(self, offset: int, whence: int) -> int`. Read more in:
3434
:ref:`sphx_glr_generated_examples_decoding_file_like.py`.
3535
stream_index (int, optional): Specifies which stream in the video to decode frames from.
3636
Note that this index is absolute across all media types. If left unspecified, then

test/test_decoders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __init__(self, file):
8686
def read(self, size: int) -> bytes:
8787
return self._file.read(size)
8888

89-
def seek(self, offset: int, whence: int) -> bytes:
89+
def seek(self, offset: int, whence: int) -> int:
9090
return self._file.seek(offset, whence)
9191

9292
source = CustomReader(open(asset.path, mode="rb", buffering=0))

test/test_ops.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ def read(self, size: int) -> bytes:
10381038
self.num_reads += 1
10391039
return self._file.read(size)
10401040

1041-
def seek(self, offset: int, whence: int) -> bytes:
1041+
def seek(self, offset: int, whence: int) -> int:
10421042
self.num_seeks += 1
10431043
return self._file.seek(offset, whence)
10441044

@@ -1086,8 +1086,8 @@ def seek(self, offset: int, whence: int) -> bytes:
10861086

10871087
def test_file_like_method_check_fails(self):
10881088
class ReadMethodMissing:
1089-
def seek(self, offset: int, whence: int) -> bytes:
1090-
return bytes()
1089+
def seek(self, offset: int, whence: int) -> int:
1090+
return 0
10911091

10921092
with pytest.raises(RuntimeError, match="must implement a read method"):
10931093
create_from_file_like(ReadMethodMissing(), "approximate")
@@ -1107,7 +1107,7 @@ def __init__(self, file: io.RawIOBase):
11071107
def read(self) -> bytes:
11081108
return bytes()
11091109

1110-
def seek(self, offset: int, whence: int) -> bytes:
1110+
def seek(self, offset: int, whence: int) -> int:
11111111
return self._file.seeK(offset, whence)
11121112

11131113
with pytest.raises(
@@ -1126,8 +1126,8 @@ def read(self, size: int) -> bytes:
11261126
return self._file.read(size)
11271127

11281128
# io.RawIOBase says we should accept two ints; wrong signature on purpose
1129-
def seek(self, offset: int) -> bytes:
1130-
return bytes()
1129+
def seek(self, offset: int) -> int:
1130+
return 0
11311131

11321132
with pytest.raises(
11331133
TypeError, match="takes 2 positional arguments but 3 were given"
@@ -1147,7 +1147,7 @@ def read(self, size: int) -> bytes:
11471147
# We intentionally read more than requested.
11481148
return self._file.read(size + 10)
11491149

1150-
def seek(self, offset: int, whence: int) -> bytes:
1150+
def seek(self, offset: int, whence: int) -> int:
11511151
return self._file.seek(offset, whence)
11521152

11531153
with pytest.raises(RuntimeError, match="does not conform to read protocol"):
@@ -1174,7 +1174,7 @@ def read(self, size: int) -> bytes:
11741174

11751175
return self._file.read(size)
11761176

1177-
def seek(self, offset: int, whence: int) -> bytes:
1177+
def seek(self, offset: int, whence: int) -> int:
11781178
return self._file.seek(offset, whence)
11791179

11801180
decoder_file_like = create_from_file_like(

0 commit comments

Comments
 (0)