Skip to content

Commit 27fa4c7

Browse files
committed
chore: type checking fl8
1 parent 7795ad6 commit 27fa4c7

7 files changed

Lines changed: 33 additions & 22 deletions

File tree

audius/cli/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import TYPE_CHECKING, Optional
22

33
from cyclopts import App
44

@@ -10,7 +10,10 @@
1010
from audius.cli.users import users
1111
from audius.cli.utils import print
1212
from audius.client_factory import get_hosts
13-
from audius.types import PlayerType
13+
14+
if TYPE_CHECKING:
15+
from audius.types import PlayerType
16+
1417

1518
audius = App()
1619
audius.command(config)
@@ -31,7 +34,7 @@ def hosts():
3134

3235

3336
@audius.command
34-
def play(track_id: Optional[str] = None, player: Optional[PlayerType] = None):
37+
def play(track_id: Optional[str] = None, player: Optional["PlayerType"] = None):
3538
"""
3639
Play something from Audius
3740
"""

audius/cli/tracks.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from pathlib import Path
2-
from typing import Optional
2+
from typing import TYPE_CHECKING, Optional
33

44
from cyclopts import App
55

66
from audius.cli.utils import print
77
from audius.const import DEFAULT_BUFFER_SIZE
88
from audius.sdk import Audius
9-
from audius.types import PlayerType
9+
10+
if TYPE_CHECKING:
11+
from audius.types import PlayerType
1012

1113
tracks = App(name="tracks", help="View and play tracks")
1214

@@ -58,7 +60,7 @@ def search(query: str = ""):
5860

5961

6062
@tracks.command(name="play")
61-
def play_track(track_id: Optional[str] = None, player: Optional[PlayerType] = None):
63+
def play_track(track_id: Optional[str] = None, player: Optional["PlayerType"] = None):
6264
"""
6365
Play a track
6466

audius/player/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from audius.client import API
44
from audius.exceptions import MissingPlayerError
55
from audius.player.af import AFPlayer
6-
from audius.player.base import BasePlayer
76
from audius.player.vlc import VLCPlayer
87
from audius.types import PlayerType
98

109
if TYPE_CHECKING:
10+
from audius.player.base import BasePlayer
1111
from audius.sdk import Audius
1212

1313

@@ -18,7 +18,7 @@ def __init__(self, sdk: "Audius") -> None:
1818
PlayerType.AFPLAY: AFPlayer,
1919
PlayerType.VLC: VLCPlayer,
2020
}
21-
self._player_map: dict[PlayerType, BasePlayer] = {}
21+
self._player_map: dict[PlayerType, "BasePlayer"] = {}
2222

2323
def play(self, url: str, player_type: Optional[PlayerType] = None):
2424
player = self.get_player(player_type=player_type)
@@ -28,7 +28,7 @@ def display_now_playing(self, track: dict, player_type: Optional[PlayerType] = N
2828
player = self.get_player(player_type=player_type)
2929
player.display_now_playing(track)
3030

31-
def get_player(self, player_type: Optional[PlayerType] = None) -> BasePlayer:
31+
def get_player(self, player_type: Optional[PlayerType] = None) -> "BasePlayer":
3232
player_type = player_type or self.config.player
3333
if player_type is not None:
3434
if player_type not in self._player_classes:

audius/player/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import click
55

66
from audius.client import API
7-
from audius.types import PlayerType
87

98
if TYPE_CHECKING:
109
from audius.sdk import Audius
10+
from audius.types import PlayerType
1111

1212

1313
class BasePlayer(API):
14-
def __init__(self, player_type: PlayerType, sdk: "Audius"):
14+
def __init__(self, player_type: "PlayerType", sdk: "Audius"):
1515
self._type = player_type
1616
super().__init__(sdk)
1717

audius/tracks.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
from collections.abc import Iterable, Iterator
33
from pathlib import Path
44
from random import randint
5-
from typing import IO, Optional, Union
5+
from typing import IO, TYPE_CHECKING, Optional, Union
66

77
import click
8-
from requests import Response
98
from requests.exceptions import HTTPError
109
from tqdm import tqdm # type: ignore
1110

1211
from audius.client import API
1312
from 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

1720
class DownloadProgressBar(tqdm):
@@ -22,8 +25,8 @@ def update_to(self, b=1, bsize=1, tsize=None):
2225

2326

2427
def _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

5558
def _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
):

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[flake8]
22
max-line-length = 100
3+
ignore = E704,W503,PYD002,TC003,TC006

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"types-requests",
1313
"types-setuptools",
1414
"flake8>=7.1.1",
15+
"flake8-type-checking",
1516
"isort>=5.13.2",
1617
"mdformat>=0.7.21",
1718
"mdformat-gfm>=0.3.5",
@@ -58,7 +59,8 @@
5859
include_package_data=True,
5960
install_requires=[
6061
"requests>=2.32.3,<3",
61-
"" "tqdm>=4.67.1,<5",
62+
"cyclopts>=3.4.1,<4",
63+
"tqdm>=4.67.1,<5",
6264
"afplay-py>=0.2.0,<0.3",
6365
],
6466
python_requires=">=3.9,<4",

0 commit comments

Comments
 (0)