Skip to content

Fix incorrect type annotations in get_writer function in utils.py #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JulianFP
Copy link

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 from ResultWriter. The __call__ method of ResultWriter 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 a str as the second argument while get_writer claims to return a callable which takes a TextIO as the second argument.

The type annotation of the __call__ method of ResultWriter is correct since the method expects a string to construct the os path, hence this PR adjusts the annotation in get_writer to fit the one of ResultWriter.

The audio_path attribute that the __call__ method of the ResultWriter class takes is a str, not TextIO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant