-
Notifications
You must be signed in to change notification settings - Fork 634
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cherry-pick] Fix backward compatibility layer in backend module (#3595…
…) (#3596) Summary: The PR #3549 re-organized the backend implementations and deprecated the direct access to torchaudio.backend. The change was supposed to be BC-compatible while issuing a warning to users, but the implementation of module-level `__getattr__` was not quite right. See an issue pyannote/pyannote-audio#1456. This commit fixes it so that the following imports work; ```python from torchaudio.backend.common import AudioMetaData from torchaudio.backend import sox_io_backend from torchaudio.backend.sox_io_backend import save, load, info from torchaudio.backend import no_backend from torchaudio.backend.no_backend import save, load, info from torchaudio.backend import soundfile_backend from torchaudio.backend.soundfile_backend import save, load, info ``` Pull Request resolved: #3595 Reviewed By: nateanl Differential Revision: D48957446 Pulled By: mthrok fbshipit-source-id: ebb256461dd3032025fd27d0455ce980888f7778
- Loading branch information
Showing
6 changed files
with
44 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def __getattr__(name: str): | ||
import warnings | ||
|
||
warnings.warn( | ||
"Torchaudio's I/O functions now support par-call bakcend dispatch. " | ||
"Importing backend implementation directly is no longer guaranteed to work. " | ||
"Please use `backend` keyword with load/save/info function, instead of " | ||
"calling the udnerlying implementation directly.", | ||
stacklevel=2, | ||
) | ||
|
||
from . import _no_backend | ||
|
||
return getattr(_no_backend, name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def __getattr__(name: str): | ||
import warnings | ||
|
||
warnings.warn( | ||
"Torchaudio's I/O functions now support par-call bakcend dispatch. " | ||
"Importing backend implementation directly is no longer guaranteed to work. " | ||
"Please use `backend` keyword with load/save/info function, instead of " | ||
"calling the udnerlying implementation directly.", | ||
stacklevel=2, | ||
) | ||
|
||
from torchaudio._backend import soundfile_backend | ||
|
||
return getattr(soundfile_backend, name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def __getattr__(name: str): | ||
import warnings | ||
|
||
warnings.warn( | ||
"Torchaudio's I/O functions now support par-call bakcend dispatch. " | ||
"Importing backend implementation directly is no longer guaranteed to work. " | ||
"Please use `backend` keyword with load/save/info function, instead of " | ||
"calling the udnerlying implementation directly.", | ||
stacklevel=2, | ||
) | ||
|
||
from . import _sox_io_backend | ||
|
||
return getattr(_sox_io_backend, name) |