Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/deepgram/core/file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was auto-generated by Fern from our API Definition.

from typing import IO, Dict, List, Mapping, Optional, Tuple, Union, cast
from typing import IO, Dict, List, Mapping, Optional, Tuple, Union

# File typing inspired by the flexibility of types within the httpx library
# https://github.com/encode/httpx/blob/master/httpx/_types.py
Expand Down Expand Up @@ -49,19 +49,18 @@ def with_content_type(*, file: File, default_content_type: str) -> File:
to the default_content_type value if not.
"""
if isinstance(file, tuple):
if len(file) == 2:
filename, content = cast(Tuple[Optional[str], FileContent], file) # type: ignore
file_len = len(file)
if file_len == 2:
filename, content = file # type: ignore
return (filename, content, default_content_type)
elif len(file) == 3:
filename, content, file_content_type = cast(Tuple[Optional[str], FileContent, Optional[str]], file) # type: ignore
elif file_len == 3:
filename, content, file_content_type = file # type: ignore
out_content_type = file_content_type or default_content_type
return (filename, content, out_content_type)
elif len(file) == 4:
filename, content, file_content_type, headers = cast( # type: ignore
Tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]], file
)
elif file_len == 4:
filename, content, file_content_type, headers = file # type: ignore
out_content_type = file_content_type or default_content_type
return (filename, content, out_content_type, headers)
else:
raise ValueError(f"Unexpected tuple length: {len(file)}")
raise ValueError(f"Unexpected tuple length: {file_len}")
return (None, file, default_content_type)