Skip to content

Commit c55c503

Browse files
committed
GH-132445: Allowing to reset parameters of Wave_write
1 parent 1e5798e commit c55c503

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Lib/wave.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def __exit__(self, *args):
478478
# User visible methods.
479479
#
480480
def setnchannels(self, nchannels):
481-
if self._datawritten:
481+
if self._datawritten and self._nchannels != nchannels:
482482
raise Error('cannot change parameters after starting to write')
483483
if nchannels < 1:
484484
raise Error('bad # of channels')
@@ -490,7 +490,7 @@ def getnchannels(self):
490490
return self._nchannels
491491

492492
def setsampwidth(self, sampwidth):
493-
if self._datawritten:
493+
if self._datawritten and self._sampwidth != sampwidth:
494494
raise Error('cannot change parameters after starting to write')
495495
if sampwidth < 1 or sampwidth > 4:
496496
raise Error('bad sample width')
@@ -502,19 +502,20 @@ def getsampwidth(self):
502502
return self._sampwidth
503503

504504
def setframerate(self, framerate):
505-
if self._datawritten:
505+
rounded_framerate = int(round(framerate))
506+
if self._datawritten and self._framerate != rounded_framerate:
506507
raise Error('cannot change parameters after starting to write')
507-
if framerate <= 0:
508+
if rounded_framerate <= 0:
508509
raise Error('bad frame rate')
509-
self._framerate = int(round(framerate))
510+
self._framerate = rounded_framerate
510511

511512
def getframerate(self):
512513
if not self._framerate:
513514
raise Error('frame rate not set')
514515
return self._framerate
515516

516517
def setnframes(self, nframes):
517-
if self._datawritten:
518+
if self._datawritten and self._nframes != nframes:
518519
raise Error('cannot change parameters after starting to write')
519520
self._nframes = nframes
520521

@@ -537,8 +538,8 @@ def getcompname(self):
537538

538539
def setparams(self, params):
539540
nchannels, sampwidth, framerate, nframes, comptype, compname = params
540-
if self._datawritten:
541-
raise Error('cannot change parameters after starting to write')
541+
# no check for value change required: either the properties have the same
542+
# value or they throw the exception them selfs
542543
self.setnchannels(nchannels)
543544
self.setsampwidth(sampwidth)
544545
self.setframerate(framerate)

0 commit comments

Comments
 (0)