Skip to content

πŸŽ› πŸ”Š A Python library for audio.

Raise any Python exceptions thrown during seek operations on file-like objects. (#262)

Peter Sobot2c35d8f3151b
diff --git a/pedalboard/io/PythonFileLike.h b/pedalboard/io/PythonFileLike.h
index 1689c0c..af16f18 100644
--- a/pedalboard/io/PythonFileLike.h
+++ b/pedalboard/io/PythonFileLike.h
@@ -109,10 +109,7 @@ public:
if (!PythonException::isPending()) {
try {
- if (fileLike.attr("seekable")().cast<bool>()) {
- fileLike.attr("seek")(pos);
- }
-
+ fileLike.attr("seek")(pos);
return fileLike.attr("tell")().cast<juce::int64>() == pos;
} catch (py::error_already_set e) {
e.restore();
diff --git a/tests/test_io.py b/tests/test_io.py
index 86c309a..a98e9a4 100644
--- a/tests/test_io.py
+++ b/tests/test_io.py
@@ -398,6 +398,19 @@ def test_no_crash_if_type_error_on_file_like():
assert "bool" in str(e)
+def test_file_like_must_be_seekable_for_write():
+ stream = io.BytesIO()
+ stream.seek = lambda x: (_ for _ in ()).throw(
+ ValueError(f"Failed to seek from {stream.tell():,} to {x:,} because I don't wanna")
+ )
+
+ with pytest.raises(ValueError) as e:
+ with pedalboard.io.AudioFile(stream, "w", 44100, 2, format="flac"):
+ pass
+
+ assert "I don't wanna" in str(e)
+
+
def test_write_fails_without_extension(tmp_path: pathlib.Path):
dest_path = str(tmp_path / "no_extension")
with pytest.raises(ValueError):