Skip to content

Commit 671cd32

Browse files
committed
#17487: wave.getparams now returns a namedtuple.
Patch by Claudiu Popa.
1 parent 3f5ffbe commit 671cd32

5 files changed

Lines changed: 38 additions & 8 deletions

File tree

Doc/library/wave.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ Wave_read objects, as returned by :func:`.open`, have the following methods:
9898

9999
.. method:: Wave_read.getparams()
100100

101-
Returns a tuple ``(nchannels, sampwidth, framerate, nframes, comptype,
102-
compname)``, equivalent to output of the :meth:`get\*` methods.
101+
Returns a :func:`~collections.namedtuple` ``(nchannels, sampwidth,
102+
framerate, nframes, comptype, compname)``, equivalent to output of the
103+
:meth:`get\*` methods.
103104

104105

105106
.. method:: Wave_read.readframes(n)

Doc/whatsnew/3.4.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ doctest
157157
Added ``FAIL_FAST`` flag to halt test running as soon as the first failure is
158158
detected. (Contributed by R. David Murray and Daniel Urban in :issue:`16522`.)
159159

160+
wave
161+
----
162+
163+
The :meth:`~wave.getparams` method now returns a namedtuple rather than a
164+
plain tuple. (Contributed by Claudiu Popa in :issue:`17487`.)
165+
160166

161167
Optimizations
162168
=============

Lib/test/test_wave.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ def test_issue7681(self):
5858
output = b'\0' * nframes * nchannels * sampwidth
5959
self.f.writeframes(output)
6060

61+
def test_getparams(self):
62+
self.f = wave.open(TESTFN, 'wb')
63+
self.f.setnchannels(nchannels)
64+
self.f.setsampwidth(sampwidth)
65+
self.f.setframerate(framerate)
66+
self.f.close()
67+
68+
self.f = wave.open(TESTFN, 'rb')
69+
params = self.f.getparams()
70+
self.assertEqual(params.nchannels, self.f.getnchannels())
71+
self.assertEqual(params.nframes, self.f.getnframes())
72+
self.assertEqual(params.sampwidth, self.f.getsampwidth())
73+
self.assertEqual(params.framerate, self.f.getframerate())
74+
self.assertEqual(params.comptype, self.f.getcomptype())
75+
self.assertEqual(params.compname, self.f.getcompname())
76+
6177

6278
def test_main():
6379
run_unittest(TestWave)

Lib/wave.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
getcomptype() -- returns compression type ('NONE' for linear samples)
1919
getcompname() -- returns human-readable version of
2020
compression type ('not compressed' linear samples)
21-
getparams() -- returns a tuple consisting of all of the
21+
getparams() -- returns a namedtuple consisting of all of the
2222
above in the above order
2323
getmarkers() -- returns None (for compatibility with the
2424
aifc module)
@@ -90,6 +90,10 @@ class Error(Exception):
9090
big_endian = 0
9191

9292
from chunk import Chunk
93+
from collections import namedtuple
94+
95+
_result = namedtuple('params',
96+
'nchannels sampwidth framerate nframes comptype compname')
9397

9498
class Wave_read:
9599
"""Variables used in this class:
@@ -206,9 +210,9 @@ def getcompname(self):
206210
return self._compname
207211

208212
def getparams(self):
209-
return self.getnchannels(), self.getsampwidth(), \
210-
self.getframerate(), self.getnframes(), \
211-
self.getcomptype(), self.getcompname()
213+
return _result(self.getnchannels(), self.getsampwidth(),
214+
self.getframerate(), self.getnframes(),
215+
self.getcomptype(), self.getcompname())
212216

213217
def getmarkers(self):
214218
return None
@@ -398,8 +402,8 @@ def setparams(self, params):
398402
def getparams(self):
399403
if not self._nchannels or not self._sampwidth or not self._framerate:
400404
raise Error('not all parameters set')
401-
return self._nchannels, self._sampwidth, self._framerate, \
402-
self._nframes, self._comptype, self._compname
405+
return _result(self._nchannels, self._sampwidth, self._framerate,
406+
self._nframes, self._comptype, self._compname)
403407

404408
def setmark(self, id, pos, name):
405409
raise Error('setmark() not supported')

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Core and Builtins
3232
Library
3333
-------
3434

35+
- Issue #17487: The wave getparams method now returns a namedtuple rather than
36+
a plain tuple.
37+
3538
- Issue #17675: socket repr() provides local and remote addresses (if any).
3639
Patch by Giampaolo Rodola'
3740

0 commit comments

Comments
 (0)