-
-
Notifications
You must be signed in to change notification settings - Fork 34.6k
gh-149306: Improve error messages in wave module to include the offending value #149307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -388,7 +388,7 @@ def readframes(self, nframes): | |||||||||||||||||
|
|
||||||||||||||||||
| def _read_fmt_chunk(self, chunk): | ||||||||||||||||||
| try: | ||||||||||||||||||
| self._format, self._nchannels, self._framerate, dwAvgBytesPerSec, wBlockAlign = struct.unpack_from('<HHLLH', chunk.read(14)) | ||||||||||||||||||
| self._format, nchannels, self._framerate, dwAvgBytesPerSec, wBlockAlign = struct.unpack_from('<HHLLH', chunk.read(14)) | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't change this. It is a breaking change. Previously the attribute would have been already set after passing |
||||||||||||||||||
| except struct.error: | ||||||||||||||||||
| raise EOFError from None | ||||||||||||||||||
| if self._format not in (WAVE_FORMAT_PCM, WAVE_FORMAT_IEEE_FLOAT, WAVE_FORMAT_EXTENSIBLE): | ||||||||||||||||||
|
|
@@ -415,9 +415,10 @@ def _read_fmt_chunk(self, chunk): | |||||||||||||||||
| raise Error(subformat_msg) | ||||||||||||||||||
| self._sampwidth = (sampwidth + 7) // 8 | ||||||||||||||||||
| if not self._sampwidth: | ||||||||||||||||||
| raise Error('bad sample width') | ||||||||||||||||||
| if not self._nchannels: | ||||||||||||||||||
| raise Error('bad # of channels') | ||||||||||||||||||
| raise Error(f'bad sample width: {sampwidth!r}') | ||||||||||||||||||
| if not nchannels: | ||||||||||||||||||
| raise Error(f'bad # of channels: {nchannels!r}') | ||||||||||||||||||
| self._nchannels = nchannels | ||||||||||||||||||
| self._framesize = self._nchannels * self._sampwidth | ||||||||||||||||||
| self._comptype = 'NONE' | ||||||||||||||||||
| self._compname = 'not compressed' | ||||||||||||||||||
|
|
@@ -495,7 +496,7 @@ def setnchannels(self, nchannels): | |||||||||||||||||
| if self._datawritten: | ||||||||||||||||||
| raise Error('cannot change parameters after starting to write') | ||||||||||||||||||
| if nchannels < 1: | ||||||||||||||||||
| raise Error('bad # of channels') | ||||||||||||||||||
| raise Error(f'bad # of channels: {nchannels!r}') | ||||||||||||||||||
| self._nchannels = nchannels | ||||||||||||||||||
|
|
||||||||||||||||||
| def getnchannels(self): | ||||||||||||||||||
|
|
@@ -510,7 +511,7 @@ def setsampwidth(self, sampwidth): | |||||||||||||||||
| if sampwidth not in (4, 8): | ||||||||||||||||||
| raise Error('unsupported sample width for IEEE float format') | ||||||||||||||||||
| elif sampwidth < 1 or sampwidth > 4: | ||||||||||||||||||
| raise Error('bad sample width') | ||||||||||||||||||
| raise Error(f'bad sample width: {sampwidth!r}') | ||||||||||||||||||
| self._sampwidth = sampwidth | ||||||||||||||||||
|
|
||||||||||||||||||
| def getsampwidth(self): | ||||||||||||||||||
|
|
@@ -521,10 +522,10 @@ def getsampwidth(self): | |||||||||||||||||
| def setframerate(self, framerate): | ||||||||||||||||||
| if self._datawritten: | ||||||||||||||||||
| raise Error('cannot change parameters after starting to write') | ||||||||||||||||||
| framerate = int(round(framerate)) | ||||||||||||||||||
| if framerate <= 0: | ||||||||||||||||||
| raise Error('bad frame rate') | ||||||||||||||||||
| self._framerate = framerate | ||||||||||||||||||
| rounded = int(round(framerate)) | ||||||||||||||||||
| if rounded <= 0: | ||||||||||||||||||
| raise Error(f'bad frame rate: {framerate!r}') | ||||||||||||||||||
| self._framerate = rounded | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| def getframerate(self): | ||||||||||||||||||
| if not self._framerate: | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Error messages in :mod:`wave` for invalid channel count, sample width, and | ||
| frame rate now include the offending value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For readability purposes, can you put the message outside?