Tree: Swap from map to list comprehensions

List comprehensions are the more "pythonic" way to approach mapping
values to a list. They're also more flexible across different collection
types rather than the inbuilt map method. It's best to keep one convention
rather than splitting down two.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri 2024-05-25 21:13:58 -04:00 committed by Brian Dashore
parent 46d0d13914
commit 9fbbc5afca
4 changed files with 20 additions and 27 deletions

View file

@ -63,15 +63,13 @@ def _get_repo_info(repo_id, revision, token):
api_client = HfApi()
repo_tree = api_client.list_repo_files(repo_id, revision=revision, token=token)
return list(
map(
lambda filename: {
"filename": filename,
"url": hf_hub_url(repo_id, filename, revision=revision),
},
repo_tree,
)
)
return [
{
"filename": filename,
"url": hf_hub_url(repo_id, filename, revision=revision),
}
for filename in repo_tree
]
def _get_download_folder(repo_id: str, repo_type: str, folder_name: Optional[str]):

View file

@ -367,7 +367,7 @@ def get_all_presets():
"""Fetches all sampler override presets from the overrides directory"""
override_directory = pathlib.Path("sampler_overrides")
preset_files = map(lambda file: file.stem, override_directory.glob("*.yml"))
preset_files = [file.stem for file in override_directory.glob("*.yml")]
return preset_files