Skip to content

Commit

Permalink
refactor: make get_builtin_repository function check for repo instance
Browse files Browse the repository at this point in the history
  • Loading branch information
chamini2 committed Jan 21, 2025
1 parent 72a7376 commit 87f6beb
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions projects/fal/src/fal/toolkit/file/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
}


def get_builtin_repository(id: RepositoryId) -> FileRepository:
def get_builtin_repository(id: RepositoryId | FileRepository) -> FileRepository:
if isinstance(id, FileRepository):
return id

if id not in BUILT_IN_REPOSITORIES.keys():
raise ValueError(f'"{id}" is not a valid built-in file repository')
return BUILT_IN_REPOSITORIES[id]()
Expand Down Expand Up @@ -139,11 +142,7 @@ def from_bytes(
save_kwargs: Optional[dict] = None,
fallback_save_kwargs: Optional[dict] = None,
) -> File:
repo = (
repository
if isinstance(repository, FileRepository)
else get_builtin_repository(repository)
)
repo = get_builtin_repository(repository)

save_kwargs = save_kwargs or {}
fallback_save_kwargs = fallback_save_kwargs or {}
Expand All @@ -160,11 +159,7 @@ def from_bytes(
if not fallback_repository:
raise

fallback_repo = (
fallback_repository
if isinstance(fallback_repository, FileRepository)
else get_builtin_repository(fallback_repository)
)
fallback_repo = get_builtin_repository(fallback_repository)

url = fallback_repo.save(
fdata, object_lifecycle_preference, **fallback_save_kwargs
Expand Down Expand Up @@ -196,11 +191,7 @@ def from_path(
if not file_path.exists():
raise FileNotFoundError(f"File {file_path} does not exist")

repo = (
repository
if isinstance(repository, FileRepository)
else get_builtin_repository(repository)
)
repo = get_builtin_repository(repository)

save_kwargs = save_kwargs or {}
fallback_save_kwargs = fallback_save_kwargs or {}
Expand All @@ -222,11 +213,7 @@ def from_path(
if not fallback_repository:
raise

fallback_repo = (
fallback_repository
if isinstance(fallback_repository, FileRepository)
else get_builtin_repository(fallback_repository)
)
fallback_repo = get_builtin_repository(fallback_repository)

url, data = fallback_repo.save_file(
file_path,
Expand Down

0 comments on commit 87f6beb

Please sign in to comment.