Skip to content

[3.14] gh-136523: Fix wave.Wave_write emitting an unraisable when open raises (GH-136529) #136606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3.14
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions Lib/test/test_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from test import audiotests
from test import support
import io
import os
import struct
import sys
import wave
Expand Down Expand Up @@ -222,6 +223,14 @@ def test_read_wrong_sample_width(self):
with self.assertRaisesRegex(wave.Error, 'bad sample width'):
wave.open(io.BytesIO(b))

def test_open_in_write_raises(self):
# gh-136523: Wave_write.__del__ should not throw
with support.catch_unraisable_exception() as cm:
with self.assertRaises(OSError):
wave.open(os.curdir, "wb")
support.gc_collect()
self.assertIsNone(cm.unraisable)


if __name__ == '__main__':
unittest.main()
2 changes: 2 additions & 0 deletions Lib/wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ class Wave_write:
_datawritten -- the size of the audio samples actually written
"""

_file = None

def __init__(self, f):
self._i_opened_the_file = None
if isinstance(f, str):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :class:`wave.Wave_write` emitting an unraisable when open raises.
Loading