]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-136523: Fix wave.Wave_write emitting an unraisable when open raises (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 13 Jul 2025 06:13:01 +0000 (08:13 +0200)
committerGitHub <noreply@github.com>
Sun, 13 Jul 2025 06:13:01 +0000 (06:13 +0000)
(cherry picked from commit 171de05b4884d1353044417ea51a4efcb55ba633)

Co-authored-by: Sachin Shah <39803835+inventshah@users.noreply.github.com>
Lib/test/test_wave.py
Lib/wave.py
Misc/NEWS.d/next/Library/2025-07-11-03-39-15.gh-issue-136523.s7caKL.rst [new file with mode: 0644]

index 5e771c8de969ec6af17653a6c06b5032548426f4..346a343761a7c1b489e4f1466cc4c8bd25297a3d 100644 (file)
@@ -2,6 +2,7 @@ import unittest
 from test import audiotests
 from test import support
 import io
+import os
 import struct
 import sys
 import wave
@@ -222,6 +223,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()
index a34af244c3e22442d9db1929e7eb0b6f9cdf6e0c..b8476e264868fc704fd4447aa02cde7c9495eac9 100644 (file)
@@ -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):
diff --git a/Misc/NEWS.d/next/Library/2025-07-11-03-39-15.gh-issue-136523.s7caKL.rst b/Misc/NEWS.d/next/Library/2025-07-11-03-39-15.gh-issue-136523.s7caKL.rst
new file mode 100644 (file)
index 0000000..71ec66a
--- /dev/null
@@ -0,0 +1 @@
+Fix :class:`wave.Wave_write` emitting an unraisable when open raises.