bpo-31985: Deprecate openfp in aifc, sunau, and wave (#4344) · python/cpython@9f914a0 (original) (raw)
12 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -63,6 +63,8 @@ The :mod:`sunau` module defines the following functions: | ||
63 | 63 | |
64 | 64 | A synonym for :func:`.open`, maintained for backwards compatibility. |
65 | 65 | |
66 | + .. deprecated-removed:: 3.7 3.9 | |
67 | + | |
66 | 68 | |
67 | 69 | The :mod:`sunau` module defines the following exception: |
68 | 70 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -51,6 +51,8 @@ The :mod:`wave` module defines the following function and exception: | ||
51 | 51 | |
52 | 52 | A synonym for :func:`.open`, maintained for backwards compatibility. |
53 | 53 | |
54 | + .. deprecated-removed:: 3.7 3.9 | |
55 | + | |
54 | 56 | |
55 | 57 | .. exception:: Error |
56 | 58 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -915,7 +915,10 @@ def open(f, mode=None): | ||
915 | 915 | else: |
916 | 916 | raise Error("mode must be 'r', 'rb', 'w', or 'wb'") |
917 | 917 | |
918 | -openfp = open # B/W compatibility | |
918 | +def openfp(f, mode=None): | |
919 | +warnings.warn("aifc.openfp is deprecated since Python 3.7. " | |
920 | +"Use aifc.open instead.", DeprecationWarning, stacklevel=2) | |
921 | +return open(f, mode=mode) | |
919 | 922 | |
920 | 923 | if __name__ == '__main__': |
921 | 924 | import sys |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -160,7 +160,7 @@ def test_wav(h, f): | ||
160 | 160 | return None |
161 | 161 | f.seek(0) |
162 | 162 | try: |
163 | -w = wave.openfp(f, 'r') | |
163 | +w = wave.open(f, 'r') | |
164 | 164 | except (EOFError, wave.Error): |
165 | 165 | return None |
166 | 166 | return ('wav', w.getframerate(), w.getnchannels(), |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -104,6 +104,7 @@ | ||
104 | 104 | """ |
105 | 105 | |
106 | 106 | from collections import namedtuple |
107 | +import warnings | |
107 | 108 | |
108 | 109 | _sunau_params = namedtuple('_sunau_params', |
109 | 110 | 'nchannels sampwidth framerate nframes comptype compname') |
@@ -522,4 +523,7 @@ def open(f, mode=None): | ||
522 | 523 | else: |
523 | 524 | raise Error("mode must be 'r', 'rb', 'w', or 'wb'") |
524 | 525 | |
525 | -openfp = open | |
526 | +def openfp(f, mode=None): | |
527 | +warnings.warn("sunau.openfp is deprecated since Python 3.7. " | |
528 | +"Use sunau.open instead.", DeprecationWarning, stacklevel=2) | |
529 | +return open(f, mode=mode) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
1 | 1 | from test.support import findfile, TESTFN, unlink |
2 | 2 | import array |
3 | 3 | import io |
4 | +from unittest import mock | |
4 | 5 | import pickle |
5 | 6 | |
6 | 7 | |
@@ -49,6 +50,17 @@ def check_params(self, f, nchannels, sampwidth, framerate, nframes, | ||
49 | 50 | self.assertEqual(pickle.loads(dump), params) |
50 | 51 | |
51 | 52 | |
53 | +class AudioMiscTests(AudioTests): | |
54 | + | |
55 | +def test_openfp_deprecated(self): | |
56 | +arg = "arg" | |
57 | +mode = "mode" | |
58 | +with mock.patch(f"{self.module.__name__}.open") as mock_open, \ | |
59 | +self.assertWarns(DeprecationWarning): | |
60 | +self.module.openfp(arg, mode=mode) | |
61 | +mock_open.assert_called_with(arg, mode=mode) | |
62 | + | |
63 | + | |
52 | 64 | class AudioWriteTests(AudioTests): |
53 | 65 | |
54 | 66 | def create_file(self, testfile): |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -7,6 +7,7 @@ | ||
7 | 7 | import sys |
8 | 8 | import struct |
9 | 9 | import aifc |
10 | +import warnings | |
10 | 11 | |
11 | 12 | |
12 | 13 | class AifcTest(audiotests.AudioWriteTests, |
@@ -144,7 +145,9 @@ class AifcALAWTest(AifcTest, unittest.TestCase): | ||
144 | 145 | frames = byteswap(frames, 2) |
145 | 146 | |
146 | 147 | |
147 | -class AifcMiscTest(audiotests.AudioTests, unittest.TestCase): | |
148 | +class AifcMiscTest(audiotests.AudioMiscTests, unittest.TestCase): | |
149 | +module = aifc | |
150 | + | |
148 | 151 | def test_skipunknown(self): |
149 | 152 | #Issue 2245 |
150 | 153 | #This file contains chunk types aifc doesn't recognize. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -223,6 +223,8 @@ def test_others(self): | ||
223 | 223 | cm('random', ignore=('Random',)) # from _random import Random as CoreGenerator |
224 | 224 | cm('cgi', ignore=('log',)) # set with = in module |
225 | 225 | cm('pickle', ignore=('partial',)) |
226 | +# TODO(briancurtin): openfp is deprecated as of 3.7. | |
227 | +# Update this once it has been removed. | |
226 | 228 | cm('aifc', ignore=('openfp', '_aifc_params')) # set with = in module |
227 | 229 | cm('sre_parse', ignore=('dump', 'groups', 'pos')) # from sre_constants import *; property |
228 | 230 | cm('pdb') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -117,5 +117,9 @@ class SunauULAWTest(SunauTest, unittest.TestCase): | ||
117 | 117 | frames = byteswap(frames, 2) |
118 | 118 | |
119 | 119 | |
120 | +class SunauMiscTests(audiotests.AudioMiscTests, unittest.TestCase): | |
121 | +module = sunau | |
122 | + | |
123 | + | |
120 | 124 | if __name__ == "__main__": |
121 | 125 | unittest.main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -103,7 +103,9 @@ class WavePCM32Test(WaveTest, unittest.TestCase): | ||
103 | 103 | frames = byteswap(frames, 4) |
104 | 104 | |
105 | 105 | |
106 | -class MiscTestCase(unittest.TestCase): | |
106 | +class MiscTestCase(audiotests.AudioMiscTests, unittest.TestCase): | |
107 | +module = wave | |
108 | + | |
107 | 109 | def test__all__(self): |
108 | 110 | blacklist = {'WAVE_FORMAT_PCM'} |
109 | 111 | support.check__all__(self, wave, blacklist=blacklist) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -87,6 +87,7 @@ class Error(Exception): | ||
87 | 87 | import sys |
88 | 88 | from chunk import Chunk |
89 | 89 | from collections import namedtuple |
90 | +import warnings | |
90 | 91 | |
91 | 92 | _wave_params = namedtuple('_wave_params', |
92 | 93 | 'nchannels sampwidth framerate nframes comptype compname') |
@@ -502,4 +503,7 @@ def open(f, mode=None): | ||
502 | 503 | else: |
503 | 504 | raise Error("mode must be 'r', 'rb', 'w', or 'wb'") |
504 | 505 | |
505 | -openfp = open # B/W compatibility | |
506 | +def openfp(f, mode=None): | |
507 | +warnings.warn("wave.openfp is deprecated since Python 3.7. " | |
508 | +"Use wave.open instead.", DeprecationWarning, stacklevel=2) | |
509 | +return open(f, mode=mode) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
1 | +Formally deprecated aifc.openfp, sunau.openfp, and wave.openfp. Since change | |
2 | +7bc817d5ba917528e8bd07ec461c635291e7b06a in 1993, openfp in each of the three | |
3 | +modules had been pointing to that module's open funciton as a matter of | |
4 | +backwards compatibility, though it had been both untested and undocumented. |