Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Doc/library/sunau.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 2 additions & 0 deletions Doc/library/wave.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion Lib/aifc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment that test_pyclbr.py should be updated after removing openfp.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment added. After this merges I'm going to create an issue in Roundup and assign it to myself so it gets formally tracked.

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
Expand Down
2 changes: 1 addition & 1 deletion Lib/sndhdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 5 additions & 1 deletion Lib/sunau.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"""

from collections import namedtuple
import warnings

_sunau_params = namedtuple('_sunau_params',
'nchannels sampwidth framerate nframes comptype compname')
Expand Down Expand Up @@ -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)
12 changes: 12 additions & 0 deletions Lib/test/audiotests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from test.support import findfile, TESTFN, unlink
import array
import io
from unittest import mock
import pickle


Expand Down Expand Up @@ -49,6 +50,17 @@ def check_params(self, f, nchannels, sampwidth, framerate, nframes,
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):
Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_aifc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import struct
import aifc
import warnings


class AifcTest(audiotests.AudioWriteTests,
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_pyclbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ def test_others(self):
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')
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_sunau.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 3 additions & 1 deletion Lib/test/test_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion Lib/wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Error(Exception):
import sys
from chunk import Chunk
from collections import namedtuple
import warnings

_wave_params = namedtuple('_wave_params',
'nchannels sampwidth framerate nframes comptype compname')
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -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.