mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-136523: Fix wave.Wave_write emitting an unraisable when open raises (GH-136529)
This commit is contained in:
parent
42b251bceb
commit
171de05b48
3 changed files with 12 additions and 0 deletions
|
@ -2,6 +2,7 @@ import unittest
|
|||
from test import audiotests
|
||||
from test import support
|
||||
import io
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
import wave
|
||||
|
@ -196,6 +197,14 @@ class WaveLowLevelTest(unittest.TestCase):
|
|||
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()
|
||||
|
|
|
@ -427,6 +427,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):
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fix :class:`wave.Wave_write` emitting an unraisable when open raises.
|
Loading…
Add table
Add a link
Reference in a new issue