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

(cherry picked from commit 171de05b48)

Co-authored-by: Sachin Shah <39803835+inventshah@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2025-07-16 09:26:52 +02:00 committed by GitHub
parent cdf98c3b7e
commit 677b0e314c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 0 deletions

View file

@ -2,6 +2,7 @@
from test import audiotests from test import audiotests
from test import support from test import support
import io import io
import os
import struct import struct
import sys import sys
import wave import wave
@ -222,6 +223,14 @@ def test_read_wrong_sample_width(self):
with self.assertRaisesRegex(wave.Error, 'bad sample width'): with self.assertRaisesRegex(wave.Error, 'bad sample width'):
wave.open(io.BytesIO(b)) 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__': if __name__ == '__main__':
unittest.main() unittest.main()

View file

@ -441,6 +441,8 @@ class Wave_write:
_datawritten -- the size of the audio samples actually written _datawritten -- the size of the audio samples actually written
""" """
_file = None
def __init__(self, f): def __init__(self, f):
self._i_opened_the_file = None self._i_opened_the_file = None
if isinstance(f, str): if isinstance(f, str):

View file

@ -0,0 +1 @@
Fix :class:`wave.Wave_write` emitting an unraisable when open raises.