Skip to content

Commit c438649

Browse files
[3.13] gh-136523: Fix wave.Wave_write emitting an unraisable when open raises (GH-136529) (GH-136607)
(cherry picked from commit 171de05) Co-authored-by: Sachin Shah <[email protected]>
1 parent bec9bdf commit c438649

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Lib/test/test_wave.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from test import audiotests
33
from test import support
44
import io
5+
import os
56
import struct
67
import sys
78
import wave
@@ -222,6 +223,14 @@ def test_read_wrong_sample_width(self):
222223
with self.assertRaisesRegex(wave.Error, 'bad sample width'):
223224
wave.open(io.BytesIO(b))
224225

226+
def test_open_in_write_raises(self):
227+
# gh-136523: Wave_write.__del__ should not throw
228+
with support.catch_unraisable_exception() as cm:
229+
with self.assertRaises(OSError):
230+
wave.open(os.curdir, "wb")
231+
support.gc_collect()
232+
self.assertIsNone(cm.unraisable)
233+
225234

226235
if __name__ == '__main__':
227236
unittest.main()

Lib/wave.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ class Wave_write:
441441
_datawritten -- the size of the audio samples actually written
442442
"""
443443

444+
_file = None
445+
444446
def __init__(self, f):
445447
self._i_opened_the_file = None
446448
if isinstance(f, str):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix :class:`wave.Wave_write` emitting an unraisable when open raises.

0 commit comments

Comments
 (0)