Skip to content

Commit 9f914a0

Browse files
authored
bpo-31985: Deprecate openfp in aifc, sunau, and wave (#4344)
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.
1 parent 5e0df74 commit 9f914a0

12 files changed

Lines changed: 48 additions & 6 deletions

File tree

Doc/library/sunau.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ The :mod:`sunau` module defines the following functions:
6363

6464
A synonym for :func:`.open`, maintained for backwards compatibility.
6565

66+
.. deprecated-removed:: 3.7 3.9
67+
6668

6769
The :mod:`sunau` module defines the following exception:
6870

Doc/library/wave.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ The :mod:`wave` module defines the following function and exception:
5151

5252
A synonym for :func:`.open`, maintained for backwards compatibility.
5353

54+
.. deprecated-removed:: 3.7 3.9
55+
5456

5557
.. exception:: Error
5658

Lib/aifc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,10 @@ def open(f, mode=None):
915915
else:
916916
raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
917917

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)
919922

920923
if __name__ == '__main__':
921924
import sys

Lib/sndhdr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_wav(h, f):
160160
return None
161161
f.seek(0)
162162
try:
163-
w = wave.openfp(f, 'r')
163+
w = wave.open(f, 'r')
164164
except (EOFError, wave.Error):
165165
return None
166166
return ('wav', w.getframerate(), w.getnchannels(),

Lib/sunau.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"""
105105

106106
from collections import namedtuple
107+
import warnings
107108

108109
_sunau_params = namedtuple('_sunau_params',
109110
'nchannels sampwidth framerate nframes comptype compname')
@@ -522,4 +523,7 @@ def open(f, mode=None):
522523
else:
523524
raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
524525

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)

Lib/test/audiotests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from test.support import findfile, TESTFN, unlink
22
import array
33
import io
4+
from unittest import mock
45
import pickle
56

67

@@ -49,6 +50,17 @@ def check_params(self, f, nchannels, sampwidth, framerate, nframes,
4950
self.assertEqual(pickle.loads(dump), params)
5051

5152

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+
5264
class AudioWriteTests(AudioTests):
5365

5466
def create_file(self, testfile):

Lib/test/test_aifc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import sys
88
import struct
99
import aifc
10+
import warnings
1011

1112

1213
class AifcTest(audiotests.AudioWriteTests,
@@ -144,7 +145,9 @@ class AifcALAWTest(AifcTest, unittest.TestCase):
144145
frames = byteswap(frames, 2)
145146

146147

147-
class AifcMiscTest(audiotests.AudioTests, unittest.TestCase):
148+
class AifcMiscTest(audiotests.AudioMiscTests, unittest.TestCase):
149+
module = aifc
150+
148151
def test_skipunknown(self):
149152
#Issue 2245
150153
#This file contains chunk types aifc doesn't recognize.

Lib/test/test_pyclbr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ def test_others(self):
223223
cm('random', ignore=('Random',)) # from _random import Random as CoreGenerator
224224
cm('cgi', ignore=('log',)) # set with = in module
225225
cm('pickle', ignore=('partial',))
226+
# TODO(briancurtin): openfp is deprecated as of 3.7.
227+
# Update this once it has been removed.
226228
cm('aifc', ignore=('openfp', '_aifc_params')) # set with = in module
227229
cm('sre_parse', ignore=('dump', 'groups', 'pos')) # from sre_constants import *; property
228230
cm('pdb')

Lib/test/test_sunau.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,9 @@ class SunauULAWTest(SunauTest, unittest.TestCase):
117117
frames = byteswap(frames, 2)
118118

119119

120+
class SunauMiscTests(audiotests.AudioMiscTests, unittest.TestCase):
121+
module = sunau
122+
123+
120124
if __name__ == "__main__":
121125
unittest.main()

Lib/test/test_wave.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ class WavePCM32Test(WaveTest, unittest.TestCase):
103103
frames = byteswap(frames, 4)
104104

105105

106-
class MiscTestCase(unittest.TestCase):
106+
class MiscTestCase(audiotests.AudioMiscTests, unittest.TestCase):
107+
module = wave
108+
107109
def test__all__(self):
108110
blacklist = {'WAVE_FORMAT_PCM'}
109111
support.check__all__(self, wave, blacklist=blacklist)

0 commit comments

Comments
 (0)