Skip to content

Commit

Permalink
fix ruff errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ploeber committed Dec 19, 2024
1 parent 0fe1bcb commit 1e1abc7
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions assemblyai/transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def __init__(
def config(self) -> types.TranscriptionConfig:
"Returns the configuration from the internal Transcript object"
if self.transcript is None:
raise ValueError("Canot access the configuration. The internal Transcript object is None.")
raise ValueError(
"Canot access the configuration. The internal Transcript object is None."
)

return types.TranscriptionConfig(
**self.transcript.dict(
Expand Down Expand Up @@ -78,7 +80,9 @@ def wait_for_completion(self) -> Self:
polls the given transcript until we have a status other than `processing` or `queued`
"""
if not self.transcript_id:
raise ValueError("Cannot wait for completion. The internal transcript ID is None.")
raise ValueError(
"Cannot wait for completion. The internal transcript ID is None."
)

while True:
# No try-except - if there is an HTTP error then surface it to user
Expand All @@ -103,7 +107,9 @@ def export_subtitles_srt(
chars_per_caption: Optional[int],
) -> str:
if not self.transcript or not self.transcript.id:
raise ValueError("Cannot export subtitles. The internal Transcript object is None.")
raise ValueError(
"Cannot export subtitles. The internal Transcript object is None."
)

return api.export_subtitles_srt(
client=self._client.http_client,
Expand All @@ -117,7 +123,9 @@ def export_subtitles_vtt(
chars_per_caption: Optional[int],
) -> str:
if not self.transcript or not self.transcript.id:
raise ValueError("Cannot export subtitles. The internal Transcript object is None.")
raise ValueError(
"Cannot export subtitles. The internal Transcript object is None."
)

return api.export_subtitles_vtt(
client=self._client.http_client,
Expand All @@ -131,7 +139,9 @@ def word_search(
words: List[str],
) -> List[types.WordSearchMatch]:
if not self.transcript or not self.transcript.id:
raise ValueError("Cannot perform word search. The internal Transcript object is None.")
raise ValueError(
"Cannot perform word search. The internal Transcript object is None."
)

response = api.word_search(
client=self._client.http_client,
Expand All @@ -143,7 +153,9 @@ def word_search(

def get_sentences(self) -> List[types.Sentence]:
if not self.transcript or not self.transcript.id:
raise ValueError("Cannot get sentences. The internal Transcript object is None.")
raise ValueError(
"Cannot get sentences. The internal Transcript object is None."
)

response = api.get_sentences(
client=self._client.http_client,
Expand All @@ -154,7 +166,9 @@ def get_sentences(self) -> List[types.Sentence]:

def get_paragraphs(self) -> List[types.Paragraph]:
if not self.transcript or not self.transcript.id:
raise ValueError("Cannot get paragraphs. The internal Transcript object is None.")
raise ValueError(
"Cannot get paragraphs. The internal Transcript object is None."
)

response = api.get_paragraphs(
client=self._client.http_client,
Expand All @@ -177,7 +191,9 @@ def get_redacted_audio_url(self) -> str:
)

if not self.transcript_id:
raise ValueError("Cannot get redacted audio url. The internal transcript ID is None.")
raise ValueError(
"Cannot get redacted audio url. The internal transcript ID is None."
)

while True:
try:
Expand Down Expand Up @@ -208,7 +224,9 @@ def save_redacted_audio(self, filepath: str):
@classmethod
def delete_by_id(cls, transcript_id: str) -> types.Transcript:
client = _client.Client.get_default()
response = api.delete_transcript(client=client.http_client, transcript_id=transcript_id)
response = api.delete_transcript(
client=client.http_client, transcript_id=transcript_id
)

return Transcript.from_response(client=client, response=response)

Expand Down Expand Up @@ -370,7 +388,7 @@ def summary(self) -> Optional[str]:
def chapters(self) -> Optional[List[types.Chapter]]:
"The list of auto-chapters results"
if not self._impl.transcript:
raise ValueError("The internal Transcript object is None.")
raise ValueError("The internal Transcript object is None.")

return self._impl.transcript.chapters

Expand Down Expand Up @@ -604,7 +622,9 @@ def __init__(
def transcript_ids(self) -> List[str]:
if any(t.id is None for t in self.transcripts):
raise ValueError("All transcripts must have a transcript ID.")
return [t.id for t in self.transcripts if t.id] # include the if check for mypy type checker
return [
t.id for t in self.transcripts if t.id
] # include the if check for mypy type checker

def add_transcript(self, transcript: Union[Transcript, str]) -> None:
if isinstance(transcript, Transcript):
Expand Down Expand Up @@ -681,13 +701,17 @@ def __iter__(self) -> Iterator[Transcript]:
return iter(self.transcripts)

@classmethod
def get_by_ids(cls, transcript_ids: List[str]) -> Union[Self, Tuple[Self, List[types.AssemblyAIError]]]:
def get_by_ids(
cls, transcript_ids: List[str]
) -> Union[Self, Tuple[Self, List[types.AssemblyAIError]]]:
return cls(transcript_ids=transcript_ids).wait_for_completion()

@classmethod
def get_by_ids_async(
cls, transcript_ids: List[str]
) -> concurrent.futures.Future[Union[Self, Tuple[Self, List[types.AssemblyAIError]]]]:
) -> concurrent.futures.Future[
Union[Self, Tuple[Self, List[types.AssemblyAIError]]]
]:
return cls(transcript_ids=transcript_ids).wait_for_completion_async()

@property
Expand Down Expand Up @@ -762,7 +786,8 @@ def wait_for_completion(
def wait_for_completion_async(
self,
return_failures: Optional[bool] = False,
) -> concurrent.futures.Future[Union[Self, Tuple[Self, List[types.AssemblyAIError]]],
) -> concurrent.futures.Future[
Union[Self, Tuple[Self, List[types.AssemblyAIError]]],
]:
return self._executor.submit(
self.wait_for_completion, return_failures=return_failures
Expand Down

0 comments on commit 1e1abc7

Please sign in to comment.