New submission from Karel <biosthez...@centrum.cz>:
The standard `wave` library tries to close a file unconditionally. I believe this is wrong. >From the docs: Wave_write.close(): Make sure nframes is correct, and close the file if it was opened by wave. *This method is called upon object collection.* [...] This leads to problems when an exception is throw when a file is open. See the following MWE: ``` from io import BytesIO import wave audio_out = BytesIO() with wave.open(audio_out, "w") as file_out: raise Exception('aaa!') Error: # channels not specified ``` Even when I remove the context manager, so it shouldn't close the file automatically, it still does, the following: ``` file_out = wave.open(audio_out, "w") raise Exception('aaa!') ``` doesn't throw an error at me immediately, but when the file_out variable is running out of scope, I get a printout saying: `Exception ignored in: <bound method Wave_write.__del__ of <wave.Wave_write object at 0x7ff549064eb8>> [...] wave.Error: # channels not specified`. Expected behaviour: When I use a Wave_write object as a context manager, it tries to close the file unconditionally (as it does now). When I call `wave.open` manually, no automatic file closing is done. ---------- components: Library (Lib) messages: 376634 nosy: biosthezerg priority: normal severity: normal status: open title: Wave shouldn't try to close an open file at all costs type: behavior versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41752> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com