Skip to content

Add pathlib.Path support for audio file I/O#475

Open
gijzelaerr wants to merge 5 commits intospotify:masterfrom
gijzelaerr:feature/pathlib-support-451
Open

Add pathlib.Path support for audio file I/O#475
gijzelaerr wants to merge 5 commits intospotify:masterfrom
gijzelaerr:feature/pathlib-support-451

Conversation

@gijzelaerr
Copy link
Copy Markdown
Member

Summary

Picks up @psobot's work from #451 to add pathlib.Path support throughout the audio file I/O API.

  • Uses os.fspath() via pybind11 to convert path-like objects to strings (PathUtils.h)
  • Adds py::object overloads in ReadableAudioFile, WriteableAudioFile, and AudioFile constructors that accept pathlib.Path (and any os.PathLike)
  • Fixes write-mode overload resolution: properly dispatches between path-like and file-like objects instead of blindly calling pathToString()
  • Updates type hints to accept Union[str, Path]

Changes from psobot's original PR

  • Fixed build errors from the original branch
  • Fixed type hint issues (pathLikeOrStr references)
  • Added proper fallback handling in write-mode overloads where pybind11 could route file-like objects to the py::object filename overload

Test plan

  • Verified pathlib.Path works end-to-end for reading and writing WAV files
  • Verified AudioFile(Path(...)) works for both read and write modes
  • All existing file-like object tests pass (pre-existing test_write_to_seekable_stream failures also present on master)
  • test_read_from_end_of_stream_produces_helpful_error_message passes locally

Closes #451

🤖 Generated with Claude Code

psobot and others added 5 commits January 13, 2026 23:32
…ects

The py::object overloads for write mode would call pathToString() without
first checking isPathLike(), causing errors when pybind11 routed file-like
objects to the wrong overload. Add proper type dispatch: check isPathLike()
first, then fall back to isWriteableFileLike(), with a clear error otherwise.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants