From 4706a3818af5adaf8eab9d2b6d2a930ddb2511c3 Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Fri, 19 May 2017 16:39:20 +0200 Subject: [PATCH] Remove 'ctype' argument from buffer_*() methods This was deprecated in Nov 2016 (#179), which was released with version 0.9.0 in Feb 2017. --- soundfile.py | 26 +++----------------------- tests/test_pysoundfile.py | 3 +++ 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/soundfile.py b/soundfile.py index ca8f3bf..4cf7a6b 100644 --- a/soundfile.py +++ b/soundfile.py @@ -979,7 +979,7 @@ def read(self, frames=-1, dtype='float64', always_2d=False, out[frames:] = fill_value return out - def buffer_read(self, frames=-1, ctype=None, dtype=None): + def buffer_read(self, frames=-1, dtype=None): """Read from the file and return data as buffer object. Reads the given number of `frames` in the given data format @@ -1008,14 +1008,13 @@ def buffer_read(self, frames=-1, ctype=None, dtype=None): """ frames = self._check_frames(frames, fill_value=None) - dtype = self._ctype_is_deprecated(ctype, dtype) ctype = self._check_dtype(dtype) cdata = _ffi.new(ctype + '[]', frames * self.channels) read_frames = self._cdata_io('read', cdata, ctype, frames) assert read_frames == frames return _ffi.buffer(cdata) - def buffer_read_into(self, buffer, ctype=None, dtype=None): + def buffer_read_into(self, buffer, dtype): """Read from the file into a given buffer object. Fills the given `buffer` with frames in the given data format @@ -1043,7 +1042,6 @@ def buffer_read_into(self, buffer, ctype=None, dtype=None): buffer_read, .read """ - dtype = self._ctype_is_deprecated(ctype, dtype) ctype = self._check_dtype(dtype) cdata, frames = self._check_buffer(buffer, ctype) frames = self._cdata_io('read', cdata, ctype, frames) @@ -1102,7 +1100,7 @@ def write(self, data): assert written == len(data) self._update_len(written) - def buffer_write(self, data, ctype=None, dtype=None): + def buffer_write(self, data, dtype): """Write audio data from a buffer/bytes object to the file. Writes the contents of `data` to the file at the current @@ -1123,7 +1121,6 @@ def buffer_write(self, data, ctype=None, dtype=None): .write, buffer_read """ - dtype = self._ctype_is_deprecated(ctype, dtype) ctype = self._check_dtype(dtype) cdata, frames = self._check_buffer(data, ctype) written = self._cdata_io('write', cdata, ctype, frames) @@ -1388,23 +1385,6 @@ def _check_dtype(self, dtype): raise ValueError("dtype must be one of {0!r}".format( sorted(_ffi_types.keys()))) - def _ctype_is_deprecated(self, ctype, dtype): - """Show warning if ctype is used instead of dtype. - - At some point, ctype arguments shall be removed and the - corresponding dtype arguments shall lose their default value. - - """ - if ctype is not None: - from warnings import warn - warn('ctype is deprecated; use dtype instead', Warning) - if dtype is not None: - raise TypeError('Use dtype instead of ctype') - for k, v in _ffi_types.items(): - if v == ctype: - return k - return dtype - def _array_io(self, action, array, frames): """Check array and call low-level IO function.""" if (array.ndim not in (1, 2) or diff --git a/tests/test_pysoundfile.py b/tests/test_pysoundfile.py index ca10325..38399b9 100644 --- a/tests/test_pysoundfile.py +++ b/tests/test_pysoundfile.py @@ -748,6 +748,9 @@ def test_buffer_read(sf_stereo_r): with pytest.raises(ValueError) as excinfo: sf_stereo_r.buffer_read(dtype='int8') assert "dtype must be one of" in str(excinfo.value) + with pytest.raises(ValueError) as excinfo: + sf_stereo_r.buffer_read() + assert "dtype must be one of" in str(excinfo.value) @xfail_from_buffer