]> granicus.if.org Git - python/commitdiff
bpo-31985: Deprecate openfp in aifc, sunau, and wave (#4344)
authorBrian Curtin <brian@python.org>
Fri, 10 Nov 2017 16:38:25 +0000 (11:38 -0500)
committerGitHub <noreply@github.com>
Fri, 10 Nov 2017 16:38:25 +0000 (11:38 -0500)
The openfp functions of aifp, sunau, and wave had pointed to the open
function of each module since 1993 as a matter of backwards
compatibility. In the case of aifc.openfp, it was both undocumented
and untested. This change begins the formal deprecation of those
openfp functions, with their removal coming in 3.9.

This additionally adds a TODO in test_pyclbr around using aifc.openfp,
though it shouldn't be changed until removal in 3.9.

12 files changed:
Doc/library/sunau.rst
Doc/library/wave.rst
Lib/aifc.py
Lib/sndhdr.py
Lib/sunau.py
Lib/test/audiotests.py
Lib/test/test_aifc.py
Lib/test/test_pyclbr.py
Lib/test/test_sunau.py
Lib/test/test_wave.py
Lib/wave.py
Misc/NEWS.d/next/Library/2017-11-08-16-51-52.bpo-31985.dE_fOB.rst [new file with mode: 0644]

index c8357e4fcc85e236d6587202ddbb316483bbefcf..2064fd7e20bfc2acf616144071d5f88649898d2c 100644 (file)
@@ -63,6 +63,8 @@ The :mod:`sunau` module defines the following functions:
 
    A synonym for :func:`.open`, maintained for backwards compatibility.
 
+   .. deprecated-removed:: 3.7 3.9
+
 
 The :mod:`sunau` module defines the following exception:
 
index a9b3205322d7d29d640b726b4ecabdc25a994112..5c315c5161757c12187b8cb27893910b730507b7 100644 (file)
@@ -51,6 +51,8 @@ The :mod:`wave` module defines the following function and exception:
 
    A synonym for :func:`.open`, maintained for backwards compatibility.
 
+   .. deprecated-removed:: 3.7 3.9
+
 
 .. exception:: Error
 
index 49a456a893ff2ef9c9fd32ee042c51b102e2596e..e51e8f8e484095c45b87d6b599a7181db697633a 100644 (file)
@@ -915,7 +915,10 @@ def open(f, mode=None):
     else:
         raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
 
-openfp = open # B/W compatibility
+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__':
     import sys
index 7ecafb40e821cdf082a2977ab2383ba2a9ac6c62..594353136f5c374effa7aa6db6f4f75e0e99eb7a 100644 (file)
@@ -160,7 +160,7 @@ def test_wav(h, f):
         return None
     f.seek(0)
     try:
-        w = wave.openfp(f, 'r')
+        w = wave.open(f, 'r')
     except (EOFError, wave.Error):
         return None
     return ('wav', w.getframerate(), w.getnchannels(),
index 0473e9e4ca15cdbc9db8367217a209efd783317d..dbad3db8392d9576b9a4feceac910eb78993d22e 100644 (file)
@@ -104,6 +104,7 @@ is destroyed.
 """
 
 from collections import namedtuple
+import warnings
 
 _sunau_params = namedtuple('_sunau_params',
                            'nchannels sampwidth framerate nframes comptype compname')
@@ -522,4 +523,7 @@ def open(f, mode=None):
     else:
         raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
 
-openfp = open
+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)
index d3e8e9ee44a13467f57d56cbffb1c1295fc28c64..0dad01722922a9a8f5a82dd1e1bda9e8487c0a42 100644 (file)
@@ -1,6 +1,7 @@
 from test.support import findfile, TESTFN, unlink
 import array
 import io
+from unittest import mock
 import pickle
 
 
@@ -49,6 +50,17 @@ class AudioTests:
             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):
 
     def create_file(self, testfile):
index a731a5136ba5fd9992a628328253beddd5116423..a064a324705799e77d11d810e30e11adbe441571 100644 (file)
@@ -7,6 +7,7 @@ import io
 import sys
 import struct
 import aifc
+import warnings
 
 
 class AifcTest(audiotests.AudioWriteTests,
@@ -144,7 +145,9 @@ class AifcALAWTest(AifcTest, unittest.TestCase):
         frames = byteswap(frames, 2)
 
 
-class AifcMiscTest(audiotests.AudioTests, unittest.TestCase):
+class AifcMiscTest(audiotests.AudioMiscTests, unittest.TestCase):
+    module = aifc
+
     def test_skipunknown(self):
         #Issue 2245
         #This file contains chunk types aifc doesn't recognize.
index 238eb71cd87a9290cb115d5805d6407f79a9f560..eaab591f74efe49676851b41cd827cc6b68a32c7 100644 (file)
@@ -223,6 +223,8 @@ class PyclbrTest(TestCase):
         cm('random', ignore=('Random',))  # from _random import Random as CoreGenerator
         cm('cgi', ignore=('log',))      # set with = in module
         cm('pickle', ignore=('partial',))
+        # TODO(briancurtin): openfp is deprecated as of 3.7.
+        # 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('pdb')
index bc1f46c0ebd306bfe47154cdfe8d7d6a7a44c60d..966224b1df5a0fd4d3dd3d7a9327bda0c71310ed 100644 (file)
@@ -117,5 +117,9 @@ class SunauULAWTest(SunauTest, unittest.TestCase):
         frames = byteswap(frames, 2)
 
 
+class SunauMiscTests(audiotests.AudioMiscTests, unittest.TestCase):
+    module = sunau
+
+
 if __name__ == "__main__":
     unittest.main()
index 8666f7269cb1f830f3a23105aad395293941939a..c5d2e02450ef579f4d9ebaf2c854d0e25cee9600 100644 (file)
@@ -103,7 +103,9 @@ class WavePCM32Test(WaveTest, unittest.TestCase):
         frames = byteswap(frames, 4)
 
 
-class MiscTestCase(unittest.TestCase):
+class MiscTestCase(audiotests.AudioMiscTests, unittest.TestCase):
+    module = wave
+
     def test__all__(self):
         blacklist = {'WAVE_FORMAT_PCM'}
         support.check__all__(self, wave, blacklist=blacklist)
index f71f7e5bf94980d2547f9d71b092b8666b476e67..cf94d5af72b4c060dc8b5625a13827d09e524fe4 100644 (file)
@@ -87,6 +87,7 @@ import struct
 import sys
 from chunk import Chunk
 from collections import namedtuple
+import warnings
 
 _wave_params = namedtuple('_wave_params',
                      'nchannels sampwidth framerate nframes comptype compname')
@@ -502,4 +503,7 @@ def open(f, mode=None):
     else:
         raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
 
-openfp = open # B/W compatibility
+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)
diff --git a/Misc/NEWS.d/next/Library/2017-11-08-16-51-52.bpo-31985.dE_fOB.rst b/Misc/NEWS.d/next/Library/2017-11-08-16-51-52.bpo-31985.dE_fOB.rst
new file mode 100644 (file)
index 0000000..9f55ef5
--- /dev/null
@@ -0,0 +1,4 @@
+Formally deprecated aifc.openfp, sunau.openfp, and wave.openfp. Since change
+7bc817d5ba917528e8bd07ec461c635291e7b06a in 1993, openfp in each of the three
+modules had been pointing to that module's open funciton as a matter of
+backwards compatibility, though it had been both untested and undocumented.