Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pedalboard_native/io/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ class AudioFile:
those classes below for documentation.
"""

def __enter__(self) -> typing.Union[ReadableAudioFile, WriteableAudioFile]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this may be tripping up Pyright, used in tests:

with pedalboard.io.AudioFile(stream, "w", 44100, 2, format=extension) as af:  # type: ignore
    af.write(cached_rand(1, 2))

...this code now seems to make Pyright think that the af could be a ReadableAudioFile, which doesn't have a write method, so we get:

/home/runner/work/pedalboard/pedalboard/tests/test_io.py
  /home/runner/work/pedalboard/pedalboard/tests/test_io.py:621:16 - error: Cannot access attribute "write" for class "ReadableAudioFile"
    Attribute "write" is unknown (reportAttributeAccessIssue)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah. I'm not sure how to make everybody happy.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I found a solution in 999ce47.

"""
Use this :class:`AudioFile` as a context manager, automatically closing the file and releasing resources when the context manager exits.
"""

def __exit__(self, arg0: object, arg1: object, arg2: object) -> None:
"""
Stop using this :class:`AudioFile` as a context manager, close the file, release its resources.
"""

@classmethod
@typing.overload
def __new__(cls, filename: str) -> ReadableAudioFile:
Expand Down
Loading