Fix incorrect type annotations in get_writer function in utils.py #1144
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed the following issue while trying to use WhisperX's output writing capabilities from within python code for my own project called Project-W. It is not exactly major however it results in my IDE complaining about incorrect types when calling the output of
get_writer
with a string as the second attribute. If I pass a TextIO instead as the type annotation suggests it fails. Here the more in-depth explanation:The
get_writer
function returns a Callable which is currently annotated as follows:Callable[[dict, TextIO, dict], None]
.get_writer
then returns instances of writers (e.g.WriteJSON
,WriteSRT
) which all inherit fromResultWriter
. The__call__
method ofResultWriter
however is annotated like this:def __call__(self, result: dict, audio_path: str, options: dict):
. These two annotations contradict each other because the__call__
method takes astr
as the second argument whileget_writer
claims to return a callable which takes aTextIO
as the second argument.The type annotation of the
__call__
method ofResultWriter
is correct since the method expects a string to construct the os path, hence this PR adjusts the annotation inget_writer
to fit the one ofResultWriter
.