22from collections .abc import Iterable , Iterator
33from pathlib import Path
44from random import randint
5- from typing import IO , Optional , Union
5+ from typing import IO , TYPE_CHECKING , Optional , Union
66
77import click
8- from requests import Response
98from requests .exceptions import HTTPError
109from tqdm import tqdm # type: ignore
1110
1211from audius .client import API
1312from audius .exceptions import OutputPathError , TrackNotFoundError
14- from audius .types import FileDestination , PlayerType
13+
14+ if TYPE_CHECKING :
15+ from requests import Response
16+
17+ from audius .types import FileDestination , PlayerType
1518
1619
1720class DownloadProgressBar (tqdm ):
@@ -22,8 +25,8 @@ def update_to(self, b=1, bsize=1, tsize=None):
2225
2326
2427def _write_response (
25- output_paths : list [FileDestination ],
26- response : Response ,
28+ output_paths : list [" FileDestination" ],
29+ response : " Response" ,
2730 progress_bar : Optional [DownloadProgressBar ] = None ,
2831 chunk_size : int = 1 ,
2932):
@@ -53,9 +56,9 @@ def _write_response(
5356
5457
5558def _validate_output_paths (
56- output_paths : Union [FileDestination , Iterable [FileDestination ]],
57- ) -> list [FileDestination ]:
58- output_path_ls : list [FileDestination ]
59+ output_paths : Union [" FileDestination" , Iterable [" FileDestination" ]],
60+ ) -> list [" FileDestination" ]:
61+ output_path_ls : list [" FileDestination" ]
5962 if not isinstance (output_paths , (list , tuple )):
6063 output_path_ls = [output_paths ] # type: ignore
6164 else :
@@ -88,7 +91,7 @@ def search(self, query: str = "") -> list[dict]:
8891 result = self .client .get ("tracks/search" , params = {"query" : query })
8992 return result .get ("data" , [])
9093
91- def play (self , track_id : Optional [str ], player : Optional [PlayerType ] = None ):
94+ def play (self , track_id : Optional [str ], player : Optional [" PlayerType" ] = None ):
9295 if track_id is None :
9396 # Get a random track.
9497 result = self .search ()
@@ -107,7 +110,7 @@ def play(self, track_id: Optional[str], player: Optional[PlayerType] = None):
107110 def download (
108111 self ,
109112 track_id : str ,
110- output_paths : Union [FileDestination , Iterable [FileDestination ]],
113+ output_paths : Union [" FileDestination" , Iterable [" FileDestination" ]],
111114 hide_output : bool = False ,
112115 chunk_size : int = 1 ,
113116 ):
0 commit comments