Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 12 additions & 0 deletions Lib/test/test_wave.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
from test import audiotests
from test import support
from test.support import os_helper
import io
import struct
import sys
Expand Down Expand Up @@ -196,6 +197,17 @@ def test_read_wrong_sample_width(self):
with self.assertRaisesRegex(wave.Error, 'bad sample width'):
wave.open(io.BytesIO(b))

def test_write_to_protected_location(self):
# gh-136523: Wave_write.__del__ should not throw
with support.catch_unraisable_exception() as cm:
try:
with os_helper.temp_dir() as path:
wave.open(path, "wb")
except IsADirectoryError:
pass
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 @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :class:`wave.Wave_write` emitting an unraisable :exc:`AttributeError` when attempting to open an unwritable file.
Loading