Skip to content

Commit 5499e40

Browse files
committed
Fix FutureWarning: functools.partial in Python 3.13
`FutureWarning: functools.partial will be a method descriptor in future Python versions; wrap it in staticmethod() if you want to preserve the old behavior`
1 parent dc9c6b2 commit 5499e40

File tree

11 files changed

+41
-41
lines changed

11 files changed

+41
-41
lines changed

test/torchaudio_unittest/backend/dispatcher/ffmpeg/info_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
@skipIfNoExec("sox")
3535
@skipIfNoFFmpeg
3636
class TestInfo(TempDirMixin, PytorchTestCase):
37-
_info = partial(get_info_func(), backend="ffmpeg")
37+
_info = staticmethod(partial(get_info_func(), backend="ffmpeg"))
3838

3939
def test_pathlike(self):
4040
"""FFmpeg dispatcher can query audio data from pathlike object"""
@@ -315,7 +315,7 @@ def test_gsm(self):
315315
@skipIfNoExec("sox")
316316
@skipIfNoFFmpeg
317317
class TestInfoOpus(PytorchTestCase):
318-
_info = partial(get_info_func(), backend="ffmpeg")
318+
_info = staticmethod(partial(get_info_func(), backend="ffmpeg"))
319319

320320
@parameterized.expand(
321321
list(
@@ -341,7 +341,7 @@ def test_opus(self, bitrate, num_channels, compression_level):
341341
@skipIfNoExec("sox")
342342
@skipIfNoFFmpeg
343343
class TestLoadWithoutExtension(PytorchTestCase):
344-
_info = partial(get_info_func(), backend="ffmpeg")
344+
_info = staticmethod(partial(get_info_func(), backend="ffmpeg"))
345345

346346
def test_mp3(self):
347347
"""MP3 file without extension can be loaded
@@ -405,7 +405,7 @@ def read(self, n):
405405

406406
@skipIfNoExec("sox")
407407
class TestFileObject(FileObjTestBase, PytorchTestCase):
408-
_info = partial(get_info_func(), backend="ffmpeg")
408+
_info = staticmethod(partial(get_info_func(), backend="ffmpeg"))
409409

410410
def _query_fileobj(self, ext, dtype, sample_rate, num_channels, num_frames, *, comments=None):
411411
path = self._gen_file(ext, dtype, sample_rate, num_channels, num_frames, comments=comments)
@@ -557,7 +557,7 @@ def test_tarfile(self, ext, dtype):
557557
@skipIfNoExec("sox")
558558
@skipIfNoModule("requests")
559559
class TestFileObjectHttp(HttpServerMixin, FileObjTestBase, PytorchTestCase):
560-
_info = partial(get_info_func(), backend="ffmpeg")
560+
_info = staticmethod(partial(get_info_func(), backend="ffmpeg"))
561561

562562
def _query_http(self, ext, dtype, sample_rate, num_channels, num_frames):
563563
audio_path = self._gen_file(ext, dtype, sample_rate, num_channels, num_frames)
@@ -600,7 +600,7 @@ def test_requests(self, ext, dtype):
600600
@skipIfNoExec("sox")
601601
@skipIfNoFFmpeg
602602
class TestInfoNoSuchFile(PytorchTestCase):
603-
_info = partial(get_info_func(), backend="ffmpeg")
603+
_info = staticmethod(partial(get_info_func(), backend="ffmpeg"))
604604

605605
def test_info_fail(self):
606606
"""

test/torchaudio_unittest/backend/dispatcher/ffmpeg/load_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
class LoadTestBase(TempDirMixin, PytorchTestCase):
36-
_load = partial(get_load_func(), backend="ffmpeg")
36+
_load = staticmethod(partial(get_load_func(), backend="ffmpeg"))
3737

3838
def assert_format(
3939
self,
@@ -324,7 +324,7 @@ def test_amb(self, dtype, num_channels, normalize, sample_rate=8000):
324324
@skipIfNoExec("sox")
325325
@skipIfNoFFmpeg
326326
class TestLoadWithoutExtension(PytorchTestCase):
327-
_load = partial(get_load_func(), backend="ffmpeg")
327+
_load = staticmethod(partial(get_load_func(), backend="ffmpeg"))
328328

329329
def test_mp3(self):
330330
"""MP3 file without extension can be loaded
@@ -364,7 +364,7 @@ class TestFileObject(TempDirMixin, PytorchTestCase):
364364
because `load` function is rigrously tested for file path inputs to match libsox's result,
365365
"""
366366

367-
_load = partial(get_load_func(), backend="ffmpeg")
367+
_load = staticmethod(partial(get_load_func(), backend="ffmpeg"))
368368

369369
@parameterized.expand(
370370
[
@@ -541,7 +541,7 @@ def read(self, n):
541541
@skipIfNoExec("sox")
542542
@skipIfNoModule("requests")
543543
class TestFileObjectHttp(HttpServerMixin, PytorchTestCase):
544-
_load = partial(get_load_func(), backend="ffmpeg")
544+
_load = staticmethod(partial(get_load_func(), backend="ffmpeg"))
545545

546546
@parameterized.expand(
547547
[
@@ -606,7 +606,7 @@ def test_frame(self, frame_offset, num_frames):
606606
@skipIfNoExec("sox")
607607
@skipIfNoFFmpeg
608608
class TestLoadNoSuchFile(PytorchTestCase):
609-
_load = partial(get_load_func(), backend="ffmpeg")
609+
_load = staticmethod(partial(get_load_func(), backend="ffmpeg"))
610610

611611
def test_load_fail(self):
612612
"""

test/torchaudio_unittest/backend/dispatcher/ffmpeg/save_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _convert_audio_file(src_path, dst_path, muxer=None, encoder=None, sample_fmt
4141

4242

4343
class SaveTestBase(TempDirMixin, TorchaudioTestCase):
44-
_save = partial(get_save_func(), backend="ffmpeg")
44+
_save = staticmethod(partial(get_save_func(), backend="ffmpeg"))
4545

4646
def assert_save_consistency(
4747
self,
@@ -398,7 +398,7 @@ def test_save_multi_channels(self, num_channels):
398398
class TestSaveParams(TempDirMixin, PytorchTestCase):
399399
"""Test the correctness of optional parameters of `self._save`"""
400400

401-
_save = partial(get_save_func(), backend="ffmpeg")
401+
_save = staticmethod(partial(get_save_func(), backend="ffmpeg"))
402402

403403
@parameterized.expand([(True,), (False,)], name_func=name_func)
404404
def test_save_channels_first(self, channels_first):
@@ -444,7 +444,7 @@ def test_save_tensor_preserve(self, dtype):
444444
@skipIfNoExec("sox")
445445
@skipIfNoFFmpeg
446446
class TestSaveNonExistingDirectory(PytorchTestCase):
447-
_save = partial(get_save_func(), backend="ffmpeg")
447+
_save = staticmethod(partial(get_save_func(), backend="ffmpeg"))
448448

449449
def test_save_fail(self):
450450
"""

test/torchaudio_unittest/backend/dispatcher/soundfile/info_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
@skipIfNoModule("soundfile")
2626
class TestInfo(TempDirMixin, PytorchTestCase):
27-
_info = partial(get_info_func(), backend="soundfile")
27+
_info = staticmethod(partial(get_info_func(), backend="soundfile"))
2828

2929
@parameterize(
3030
["float32", "int32", "int16", "uint8"],
@@ -127,7 +127,7 @@ class MockSoundFileInfo:
127127

128128
@skipIfNoModule("soundfile")
129129
class TestFileObject(TempDirMixin, PytorchTestCase):
130-
_info = partial(get_info_func(), backend="soundfile")
130+
_info = staticmethod(partial(get_info_func(), backend="soundfile"))
131131

132132
def _test_fileobj(self, ext, subtype, bits_per_sample):
133133
"""Query audio via file-like object works"""

test/torchaudio_unittest/backend/dispatcher/soundfile/load_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __exit__(self, *args, **kwargs):
9797

9898

9999
class MockedLoadTest(PytorchTestCase):
100-
_load = partial(get_load_func(), backend="soundfile")
100+
_load = staticmethod(partial(get_load_func(), backend="soundfile"))
101101

102102
def assert_dtype(self, ext, dtype, sample_rate, num_channels, normalize, channels_first):
103103
"""When format is WAV or NIST, normalize=False will return the native dtype Tensor, otherwise float32"""
@@ -143,7 +143,7 @@ def test_flac(self, sample_rate, num_channels, normalize, channels_first):
143143

144144

145145
class LoadTestBase(TempDirMixin, PytorchTestCase):
146-
_load = partial(get_load_func(), backend="soundfile")
146+
_load = staticmethod(partial(get_load_func(), backend="soundfile"))
147147

148148
def assert_wav(
149149
self,
@@ -272,7 +272,7 @@ def test_flac(self, dtype, sample_rate, num_channels, channels_first):
272272
class TestLoadFormat(TempDirMixin, PytorchTestCase):
273273
"""Given `format` parameter, `so.load` can load files without extension"""
274274

275-
_load = partial(get_load_func(), backend="soundfile")
275+
_load = staticmethod(partial(get_load_func(), backend="soundfile"))
276276
original = None
277277
path = None
278278

@@ -314,7 +314,7 @@ def test_flac(self, format_):
314314

315315
@skipIfNoModule("soundfile")
316316
class TestFileObject(TempDirMixin, PytorchTestCase):
317-
_load = partial(get_load_func(), backend="soundfile")
317+
_load = staticmethod(partial(get_load_func(), backend="soundfile"))
318318

319319
def _test_fileobj(self, ext):
320320
"""Loading audio via file-like object works"""

test/torchaudio_unittest/backend/dispatcher/soundfile/save_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
class MockedSaveTest(PytorchTestCase):
24-
_save = partial(get_save_func(), backend="soundfile")
24+
_save = staticmethod(partial(get_save_func(), backend="soundfile"))
2525

2626
@nested_params(
2727
["float32", "int32", "int16", "uint8"],
@@ -168,7 +168,7 @@ def test_ogg(self, dtype, sample_rate, num_channels, channels_first):
168168

169169
@skipIfNoModule("soundfile")
170170
class SaveTestBase(TempDirMixin, PytorchTestCase):
171-
_save = partial(get_save_func(), backend="soundfile")
171+
_save = staticmethod(partial(get_save_func(), backend="soundfile"))
172172

173173
def assert_wav(self, dtype, sample_rate, num_channels, num_frames):
174174
"""`self._save` can save wav format."""
@@ -264,7 +264,7 @@ def test_ogg(self, sample_rate, num_channels):
264264
class TestSaveParams(TempDirMixin, PytorchTestCase):
265265
"""Test the correctness of optional parameters of `self._save`"""
266266

267-
_save = partial(get_save_func(), backend="soundfile")
267+
_save = staticmethod(partial(get_save_func(), backend="soundfile"))
268268

269269
@parameterize([True, False])
270270
def test_channels_first(self, channels_first):
@@ -279,7 +279,7 @@ def test_channels_first(self, channels_first):
279279

280280
@skipIfNoModule("soundfile")
281281
class TestFileObject(TempDirMixin, PytorchTestCase):
282-
_save = partial(get_save_func(), backend="soundfile")
282+
_save = staticmethod(partial(get_save_func(), backend="soundfile"))
283283

284284
def _test_fileobj(self, ext):
285285
"""Saving audio to file-like object works"""

test/torchaudio_unittest/backend/dispatcher/sox/info_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
@skipIfNoExec("sox")
3232
@skipIfNoSox
3333
class TestInfo(TempDirMixin, PytorchTestCase):
34-
_info = partial(get_info_func(), backend="sox")
34+
_info = staticmethod(partial(get_info_func(), backend="sox"))
3535

3636
@parameterized.expand(
3737
list(
@@ -262,7 +262,7 @@ def test_htk(self):
262262
@disabledInCI
263263
@skipIfNoSoxDecoder("opus")
264264
class TestInfoOpus(PytorchTestCase):
265-
_info = partial(get_info_func(), backend="sox")
265+
_info = staticmethod(partial(get_info_func(), backend="sox"))
266266

267267
@parameterized.expand(
268268
list(
@@ -321,7 +321,7 @@ def read(self, n):
321321
@skipIfNoSox
322322
@skipIfNoExec("sox")
323323
class TestFileObject(FileObjTestBase, PytorchTestCase):
324-
_info = partial(get_info_func(), backend="sox")
324+
_info = staticmethod(partial(get_info_func(), backend="sox"))
325325

326326
def _query_fileobj(self, ext, dtype, sample_rate, num_channels, num_frames, *, comments=None):
327327
path = self._gen_file(ext, dtype, sample_rate, num_channels, num_frames, comments=comments)
@@ -353,7 +353,7 @@ def test_fileobj(self, ext, dtype):
353353
@skipIfNoExec("sox")
354354
@skipIfNoModule("requests")
355355
class TestFileObjectHttp(HttpServerMixin, FileObjTestBase, PytorchTestCase):
356-
_info = partial(get_info_func(), backend="sox")
356+
_info = staticmethod(partial(get_info_func(), backend="sox"))
357357

358358
def _query_http(self, ext, dtype, sample_rate, num_channels, num_frames):
359359
audio_path = self._gen_file(ext, dtype, sample_rate, num_channels, num_frames)
@@ -387,7 +387,7 @@ def test_requests(self, ext, dtype):
387387

388388
@skipIfNoSox
389389
class TestInfoNoSuchFile(PytorchTestCase):
390-
_info = partial(get_info_func(), backend="sox")
390+
_info = staticmethod(partial(get_info_func(), backend="sox"))
391391

392392
def test_info_fail(self):
393393
"""

test/torchaudio_unittest/backend/dispatcher/sox/load_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
class LoadTestBase(TempDirMixin, PytorchTestCase):
25-
_load = partial(get_load_func(), backend="sox")
25+
_load = staticmethod(partial(get_load_func(), backend="sox"))
2626

2727
def assert_format(
2828
self,
@@ -293,7 +293,7 @@ def test_amr_nb(self):
293293
class TestLoadParams(TempDirMixin, PytorchTestCase):
294294
"""Test the correctness of frame parameters of `sox_io_backend.load`"""
295295

296-
_load = partial(get_load_func(), backend="sox")
296+
_load = staticmethod(partial(get_load_func(), backend="sox"))
297297

298298
def _test(self, func, frame_offset, num_frames, channels_first, normalize):
299299
original = get_wav_data("int16", num_channels=2, normalize=False)
@@ -329,7 +329,7 @@ class TestFileObject(TempDirMixin, PytorchTestCase):
329329
because `load` function is rigrously tested for file path inputs to match libsox's result,
330330
"""
331331

332-
_load = partial(get_load_func(), backend="sox")
332+
_load = staticmethod(partial(get_load_func(), backend="sox"))
333333

334334
@parameterized.expand(
335335
[
@@ -360,7 +360,7 @@ def test_fileobj(self, ext, kwargs):
360360

361361
@skipIfNoSox
362362
class TestLoadNoSuchFile(PytorchTestCase):
363-
_load = partial(get_load_func(), backend="sox")
363+
_load = staticmethod(partial(get_load_func(), backend="sox"))
364364

365365
def test_load_fail(self):
366366
"""

test/torchaudio_unittest/backend/dispatcher/sox/roundtrip_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
class TestRoundTripIO(TempDirMixin, PytorchTestCase):
1414
"""save/load round trip should not degrade data for lossless formats"""
1515

16-
_load = partial(get_load_func(), backend="sox")
17-
_save = partial(get_save_func(), backend="sox")
16+
_load = staticmethod(partial(get_load_func(), backend="sox"))
17+
_save = staticmethod(partial(get_save_func(), backend="sox"))
1818

1919
@parameterized.expand(
2020
list(

test/torchaudio_unittest/backend/dispatcher/sox/save_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _get_sox_encoding(encoding):
3434

3535

3636
class SaveTestBase(TempDirMixin, TorchaudioTestCase):
37-
_save = partial(get_save_func(), backend="sox")
37+
_save = staticmethod(partial(get_save_func(), backend="sox"))
3838

3939
def assert_save_consistency(
4040
self,
@@ -361,7 +361,7 @@ def test_save_multi_channels(self, num_channels):
361361
class TestSaveParams(TempDirMixin, PytorchTestCase):
362362
"""Test the correctness of optional parameters of `self._save`"""
363363

364-
_save = partial(get_save_func(), backend="sox")
364+
_save = staticmethod(partial(get_save_func(), backend="sox"))
365365

366366
@parameterized.expand([(True,), (False,)], name_func=name_func)
367367
def test_save_channels_first(self, channels_first):
@@ -405,7 +405,7 @@ def test_save_tensor_preserve(self, dtype):
405405

406406
@skipIfNoSox
407407
class TestSaveNonExistingDirectory(PytorchTestCase):
408-
_save = partial(get_save_func(), backend="sox")
408+
_save = staticmethod(partial(get_save_func(), backend="sox"))
409409

410410
def test_save_fail(self):
411411
"""

test/torchaudio_unittest/backend/dispatcher/sox/smoke_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class SmokeTest(TempDirMixin, TorchaudioTestCase):
1919
however without such tools, the correctness of each function cannot be verified.
2020
"""
2121

22-
_info = partial(get_info_func(), backend="sox")
23-
_load = partial(get_load_func(), backend="sox")
24-
_save = partial(get_save_func(), backend="sox")
22+
_info = staticmethod(partial(get_info_func(), backend="sox"))
23+
_load = staticmethod(partial(get_load_func(), backend="sox"))
24+
_save = staticmethod(partial(get_save_func(), backend="sox"))
2525

2626
def run_smoke_test(self, ext, sample_rate, num_channels, *, dtype="float32"):
2727
duration = 1

0 commit comments

Comments
 (0)