fastcore
fastcore copied to clipboard
Using delegates on a method breaks TypeDispatch
Adding a delegates
decorator to a method prevents TypeDispatch
from creating the correct dispatching table.
Without delegates
, the dispatch for TensorAudio.create
is correct:
class TensorAudio(TensorBase):
@classmethod
def create(cls, fn:str|Path, **kwargs):
sig, sr = torchaudio.load(fn, **kwargs)
return cls(sig, sr=sr)
TypeDispatch(TensorAudio.create)
returns
(str,object) -> create
(Path,object) -> create
But with delegates, TypeDispatch
doesn't create the correct dispatch table:
class TensorAudio(TensorBase):
@delegates(torchaudio.load)
@classmethod
def create(cls, fn:str|Path, **kwargs):
sig, sr = torchaudio.load(fn, **kwargs)
return cls(sig, sr=sr)
TypeDispatch(TensorAudio.create)
Instead TypeDispatch(TensorAudio.create)
returns:
(str,BinaryIO) -> create
(str,str) -> create
(str,PathLike) -> create
(Path,BinaryIO) -> create
(Path,str) -> create
(Path,PathLike) -> create
The BinaryIO
, str
, and PathLike
in the type dispatch are from torchaudio.load
. It's missing (str,object)
and (Path,object)
. This incorrect dispatch prevents from TensorAudio.create
dispatching in a fastai datablock.
Previous versions of fastcore did not have this interplay between delegates
and TypeDispatch
, but I am not sure when it cropped up.
Do you want to try fixing this @warner-benjamin ?