bpo-37320: Remove openfp() of aifc, sunau and wave (GH-14169)
aifc.openfp() alias to aifc.open(), sunau.openfp() alias to sunau.open(), and wave.openfp() alias to wave.open() have been removed. They were deprecated since Python 3.7.
This commit is contained in:
parent
8fac122109
commit
ac7b1a3f32
|
@ -59,13 +59,6 @@ The :mod:`sunau` module defines the following functions:
|
||||||
or ``'wb'`` returns an :class:`AU_write` object.
|
or ``'wb'`` returns an :class:`AU_write` object.
|
||||||
|
|
||||||
|
|
||||||
.. function:: openfp(file, mode)
|
|
||||||
|
|
||||||
A synonym for :func:`.open`, maintained for backwards compatibility.
|
|
||||||
|
|
||||||
.. deprecated-removed:: 3.7 3.9
|
|
||||||
|
|
||||||
|
|
||||||
The :mod:`sunau` module defines the following exception:
|
The :mod:`sunau` module defines the following exception:
|
||||||
|
|
||||||
.. exception:: Error
|
.. exception:: Error
|
||||||
|
|
|
@ -47,13 +47,6 @@ The :mod:`wave` module defines the following function and exception:
|
||||||
.. versionchanged:: 3.4
|
.. versionchanged:: 3.4
|
||||||
Added support for unseekable files.
|
Added support for unseekable files.
|
||||||
|
|
||||||
.. function:: openfp(file, mode)
|
|
||||||
|
|
||||||
A synonym for :func:`.open`, maintained for backwards compatibility.
|
|
||||||
|
|
||||||
.. deprecated-removed:: 3.7 3.9
|
|
||||||
|
|
||||||
|
|
||||||
.. exception:: Error
|
.. exception:: Error
|
||||||
|
|
||||||
An error raised when something is impossible because it violates the WAV
|
An error raised when something is impossible because it violates the WAV
|
||||||
|
|
|
@ -122,9 +122,14 @@ Deprecated
|
||||||
Removed
|
Removed
|
||||||
=======
|
=======
|
||||||
|
|
||||||
``_dummy_thread`` and ``dummy_threading`` modules have been removed. These
|
* ``_dummy_thread`` and ``dummy_threading`` modules have been removed. These
|
||||||
modules were deprecated since Python 3.7 which requires threading support.
|
modules were deprecated since Python 3.7 which requires threading support.
|
||||||
(Contributed by Victor Stinner in :issue:`37312`.)
|
(Contributed by Victor Stinner in :issue:`37312`.)
|
||||||
|
|
||||||
|
* ``aifc.openfp()`` alias to ``aifc.open()``, ``sunau.openfp()`` alias to
|
||||||
|
``sunau.open()``, and ``wave.openfp()`` alias to ``wave.open()`` have been
|
||||||
|
removed. They were deprecated since Python 3.7.
|
||||||
|
(Contributed by Victor Stinner in :issue:`37320`.)
|
||||||
|
|
||||||
|
|
||||||
Porting to Python 3.9
|
Porting to Python 3.9
|
||||||
|
|
|
@ -138,7 +138,7 @@ import struct
|
||||||
import builtins
|
import builtins
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
__all__ = ["Error", "open", "openfp"]
|
__all__ = ["Error", "open"]
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -920,10 +920,6 @@ def open(f, mode=None):
|
||||||
else:
|
else:
|
||||||
raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
|
raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
|
||||||
|
|
||||||
def openfp(f, mode=None):
|
|
||||||
warnings.warn("aifc.openfp is deprecated since Python 3.7. "
|
|
||||||
"Use aifc.open instead.", DeprecationWarning, stacklevel=2)
|
|
||||||
return open(f, mode=mode)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
|
|
|
@ -104,7 +104,7 @@ is destroyed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import warnings
|
|
||||||
|
|
||||||
_sunau_params = namedtuple('_sunau_params',
|
_sunau_params = namedtuple('_sunau_params',
|
||||||
'nchannels sampwidth framerate nframes comptype compname')
|
'nchannels sampwidth framerate nframes comptype compname')
|
||||||
|
@ -524,8 +524,3 @@ def open(f, mode=None):
|
||||||
return Au_write(f)
|
return Au_write(f)
|
||||||
else:
|
else:
|
||||||
raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
|
raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
|
||||||
|
|
||||||
def openfp(f, mode=None):
|
|
||||||
warnings.warn("sunau.openfp is deprecated since Python 3.7. "
|
|
||||||
"Use sunau.open instead.", DeprecationWarning, stacklevel=2)
|
|
||||||
return open(f, mode=mode)
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from test.support import findfile, TESTFN, unlink
|
from test.support import findfile, TESTFN, unlink
|
||||||
import array
|
import array
|
||||||
import io
|
import io
|
||||||
from unittest import mock
|
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,17 +49,6 @@ class AudioTests:
|
||||||
self.assertEqual(pickle.loads(dump), params)
|
self.assertEqual(pickle.loads(dump), params)
|
||||||
|
|
||||||
|
|
||||||
class AudioMiscTests(AudioTests):
|
|
||||||
|
|
||||||
def test_openfp_deprecated(self):
|
|
||||||
arg = "arg"
|
|
||||||
mode = "mode"
|
|
||||||
with mock.patch(f"{self.module.__name__}.open") as mock_open, \
|
|
||||||
self.assertWarns(DeprecationWarning):
|
|
||||||
self.module.openfp(arg, mode=mode)
|
|
||||||
mock_open.assert_called_with(arg, mode=mode)
|
|
||||||
|
|
||||||
|
|
||||||
class AudioWriteTests(AudioTests):
|
class AudioWriteTests(AudioTests):
|
||||||
|
|
||||||
def create_file(self, testfile):
|
def create_file(self, testfile):
|
||||||
|
|
|
@ -143,13 +143,12 @@ class AifcALAWTest(AifcTest, unittest.TestCase):
|
||||||
frames = byteswap(frames, 2)
|
frames = byteswap(frames, 2)
|
||||||
|
|
||||||
|
|
||||||
class AifcMiscTest(audiotests.AudioMiscTests, unittest.TestCase):
|
class AifcMiscTest(unittest.TestCase):
|
||||||
module = aifc
|
|
||||||
|
|
||||||
def test_skipunknown(self):
|
def test_skipunknown(self):
|
||||||
#Issue 2245
|
#Issue 2245
|
||||||
#This file contains chunk types aifc doesn't recognize.
|
#This file contains chunk types aifc doesn't recognize.
|
||||||
self.f = aifc.open(findfile('Sine-1000Hz-300ms.aif'))
|
f = aifc.open(findfile('Sine-1000Hz-300ms.aif'))
|
||||||
|
f.close()
|
||||||
|
|
||||||
def test_close_opened_files_on_error(self):
|
def test_close_opened_files_on_error(self):
|
||||||
non_aifc_file = findfile('pluck-pcm8.wav', subdir='audiodata')
|
non_aifc_file = findfile('pluck-pcm8.wav', subdir='audiodata')
|
||||||
|
@ -172,7 +171,8 @@ class AifcMiscTest(audiotests.AudioMiscTests, unittest.TestCase):
|
||||||
f.setparams((1, 1, 1, 1, b'NONE', b''))
|
f.setparams((1, 1, 1, 1, b'NONE', b''))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
f = self.f = aifc.open(TESTFN, 'rb')
|
f = aifc.open(TESTFN, 'rb')
|
||||||
|
self.addCleanup(f.close)
|
||||||
params = f.getparams()
|
params = f.getparams()
|
||||||
self.assertEqual(params.nchannels, f.getnchannels())
|
self.assertEqual(params.nchannels, f.getnchannels())
|
||||||
self.assertEqual(params.sampwidth, f.getsampwidth())
|
self.assertEqual(params.sampwidth, f.getsampwidth())
|
||||||
|
@ -208,7 +208,8 @@ class AifcMiscTest(audiotests.AudioMiscTests, unittest.TestCase):
|
||||||
fout.setmark(2, 0, b'even')
|
fout.setmark(2, 0, b'even')
|
||||||
fout.writeframes(b'\x00')
|
fout.writeframes(b'\x00')
|
||||||
fout.close()
|
fout.close()
|
||||||
f = self.f = aifc.open(TESTFN, 'rb')
|
f = aifc.open(TESTFN, 'rb')
|
||||||
|
self.addCleanup(f.close)
|
||||||
self.assertEqual(f.getmarkers(), [(1, 0, b'odd'), (2, 0, b'even')])
|
self.assertEqual(f.getmarkers(), [(1, 0, b'odd'), (2, 0, b'even')])
|
||||||
self.assertEqual(f.getmark(1), (1, 0, b'odd'))
|
self.assertEqual(f.getmark(1), (1, 0, b'odd'))
|
||||||
self.assertEqual(f.getmark(2), (2, 0, b'even'))
|
self.assertEqual(f.getmark(2), (2, 0, b'even'))
|
||||||
|
|
|
@ -225,9 +225,7 @@ class PyclbrTest(TestCase):
|
||||||
cm('random', ignore=('Random',)) # from _random import Random as CoreGenerator
|
cm('random', ignore=('Random',)) # from _random import Random as CoreGenerator
|
||||||
cm('cgi', ignore=('log',)) # set with = in module
|
cm('cgi', ignore=('log',)) # set with = in module
|
||||||
cm('pickle', ignore=('partial', 'PickleBuffer'))
|
cm('pickle', ignore=('partial', 'PickleBuffer'))
|
||||||
# TODO(briancurtin): openfp is deprecated as of 3.7.
|
cm('aifc', ignore=('_aifc_params',)) # set with = in module
|
||||||
# Update this once it has been removed.
|
|
||||||
cm('aifc', ignore=('openfp', '_aifc_params')) # set with = in module
|
|
||||||
cm('sre_parse', ignore=('dump', 'groups', 'pos')) # from sre_constants import *; property
|
cm('sre_parse', ignore=('dump', 'groups', 'pos')) # from sre_constants import *; property
|
||||||
cm('pdb')
|
cm('pdb')
|
||||||
cm('pydoc', ignore=('input', 'output',)) # properties
|
cm('pydoc', ignore=('input', 'output',)) # properties
|
||||||
|
|
|
@ -119,10 +119,6 @@ class SunauULAWTest(SunauTest, unittest.TestCase):
|
||||||
frames = byteswap(frames, 2)
|
frames = byteswap(frames, 2)
|
||||||
|
|
||||||
|
|
||||||
class SunauMiscTests(audiotests.AudioMiscTests, unittest.TestCase):
|
|
||||||
module = sunau
|
|
||||||
|
|
||||||
|
|
||||||
class SunauLowLevelTest(unittest.TestCase):
|
class SunauLowLevelTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_read_bad_magic_number(self):
|
def test_read_bad_magic_number(self):
|
||||||
|
|
|
@ -105,9 +105,7 @@ class WavePCM32Test(WaveTest, unittest.TestCase):
|
||||||
frames = byteswap(frames, 4)
|
frames = byteswap(frames, 4)
|
||||||
|
|
||||||
|
|
||||||
class MiscTestCase(audiotests.AudioMiscTests, unittest.TestCase):
|
class MiscTestCase(unittest.TestCase):
|
||||||
module = wave
|
|
||||||
|
|
||||||
def test__all__(self):
|
def test__all__(self):
|
||||||
blacklist = {'WAVE_FORMAT_PCM'}
|
blacklist = {'WAVE_FORMAT_PCM'}
|
||||||
support.check__all__(self, wave, blacklist=blacklist)
|
support.check__all__(self, wave, blacklist=blacklist)
|
||||||
|
|
20
Lib/wave.py
20
Lib/wave.py
|
@ -71,9 +71,15 @@ The close() method is called automatically when the class instance
|
||||||
is destroyed.
|
is destroyed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from chunk import Chunk
|
||||||
|
from collections import namedtuple
|
||||||
|
import audioop
|
||||||
import builtins
|
import builtins
|
||||||
|
import struct
|
||||||
|
import sys
|
||||||
|
|
||||||
__all__ = ["open", "openfp", "Error", "Wave_read", "Wave_write"]
|
|
||||||
|
__all__ = ["open", "Error", "Wave_read", "Wave_write"]
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -82,13 +88,6 @@ WAVE_FORMAT_PCM = 0x0001
|
||||||
|
|
||||||
_array_fmts = None, 'b', 'h', None, 'i'
|
_array_fmts = None, 'b', 'h', None, 'i'
|
||||||
|
|
||||||
import audioop
|
|
||||||
import struct
|
|
||||||
import sys
|
|
||||||
from chunk import Chunk
|
|
||||||
from collections import namedtuple
|
|
||||||
import warnings
|
|
||||||
|
|
||||||
_wave_params = namedtuple('_wave_params',
|
_wave_params = namedtuple('_wave_params',
|
||||||
'nchannels sampwidth framerate nframes comptype compname')
|
'nchannels sampwidth framerate nframes comptype compname')
|
||||||
|
|
||||||
|
@ -512,8 +511,3 @@ def open(f, mode=None):
|
||||||
return Wave_write(f)
|
return Wave_write(f)
|
||||||
else:
|
else:
|
||||||
raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
|
raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
|
||||||
|
|
||||||
def openfp(f, mode=None):
|
|
||||||
warnings.warn("wave.openfp is deprecated since Python 3.7. "
|
|
||||||
"Use wave.open instead.", DeprecationWarning, stacklevel=2)
|
|
||||||
return open(f, mode=mode)
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
``aifc.openfp()`` alias to ``aifc.open()``, ``sunau.openfp()`` alias to
|
||||||
|
``sunau.open()``, and ``wave.openfp()`` alias to ``wave.open()`` have been
|
||||||
|
removed. They were deprecated since Python 3.7.
|
Loading…
Reference in New Issue