Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Улучшены аннотации типов #626

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions generate_async_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
REQUEST_METHODS = ('_request_wrapper', 'get', 'post', 'retrieve', 'download')


def gen_request(output_request_filename):
def gen_request(output_request_filename: str) -> None:
with open('yandex_music/utils/request.py', 'r', encoding='UTF-8') as f:
code = f.read()

Expand Down Expand Up @@ -47,7 +47,7 @@ def gen_request(output_request_filename):
f.write(code)


def gen_client(output_client_filename):
def gen_client(output_client_filename: str) -> None:
with open('yandex_music/client.py', 'r', encoding='UTF-8') as f:
code = f.read()

Expand Down
4 changes: 2 additions & 2 deletions generate_camel_case_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def convert_snake_case_to_camel_case(string: str) -> str:
return camel_case[0].lower() + camel_case[1:]


def _generate_code(function_name: str, intent=0) -> str:
def _generate_code(function_name: str, intent: int = 0) -> str:
camel_case_name = convert_snake_case_to_camel_case(function_name)
code = ALIAS_TEMPLATE.format(name=function_name, camel_case_name=camel_case_name)

Expand Down Expand Up @@ -85,7 +85,7 @@ def _process_file(file: str) -> None:
f.write(new_file_code)


def main():
def main() -> None:
for root, _, files in os.walk(SOURCE_FOLDER):
for file in files:
if file.endswith('.py') and file != '__init__.py':
Expand Down
7 changes: 4 additions & 3 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extend-select = [
"Q", # flake8-quotes
"S", # flake8-bandit
"ASYNC", # flake8-async
# "ANN", # flake8-annotations. Not all resolved yet
"ANN", # annotations
"C",
"BLE",
"ERA",
Expand Down Expand Up @@ -37,13 +37,14 @@ ignore = [
]

[per-file-ignores]
"examples/*.py" = ["T201", "S311", "ERA001", "INP001", "S106", "BLE001", "S603"]
"examples/*.py" = ["T201", "S311", "ERA001", "INP001", "S106", "BLE001", "S603", "ANN"]
"docs/source/conf.py" = ["INP001"]
"tests/*.py" = ["S101"] # Use of assert
"tests/*.py" = ["S101", "ANN"] # Use of assert
"tests/__init__.py" = ["F401"] # Unused import
"yandex_music/__init__.py" = ["I001"] # Import sort
"yandex_music/client*.py" = ["T201"] # print
"test.py" = ["S101", "ERA001", "T201", "E501", "F401", "F841"]
"yandex_music/utils/request*.py" = ["ANN"] # TODO(MarshalX): annotate and remove this ignore

[flake8-quotes]
docstring-quotes = "double"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class PyTest(test):
def run_tests(self):
def run_tests(self) -> None:
import pytest

sys.exit(pytest.main(['tests']))
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Account(YandexMusicObject):
child: bool = None
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
if self.uid:
self._id_attrs = (self.uid,)

Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Alert(YandexMusicObject):
close_button: bool
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.alert_id,)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/alert_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AlertButton(YandexMusicObject):
uri: str
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.text, self.uri)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/auto_renewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AutoRenewable(YandexMusicObject):
order_id: Optional[int] = None
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.expires, self.vendor, self.vendor_help_url, self.product, self.finished)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/deactivation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Deactivation(YandexMusicObject):
instructions: Optional[str] = None
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.method, self.instructions)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/non_auto_renewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NonAutoRenewable(YandexMusicObject):
end: str
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.start, self.end)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Operator(YandexMusicObject):
suspended: bool
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.product_id, self.phone)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/passport_phone.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PassportPhone(YandexMusicObject):
phone: str
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.phone,)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Permissions(YandexMusicObject):
default: List[str]
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.until, self.values, self.default)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Plus(YandexMusicObject):
is_tutorial_completed: bool
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.has_plus, self.is_tutorial_completed)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Price(YandexMusicObject):
currency: str
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.amount, self.currency)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Product(YandexMusicObject):
payment_method_types: List[str] = None
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (
self.product_id,
self.type,
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/renewable_remainder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RenewableRemainder(YandexMusicObject):
days: int
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.days,)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Status(YandexMusicObject):
userhash: Optional[str] = None
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.account, self.permissions)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Subscription(YandexMusicObject):
end: Optional[str] = None
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.non_auto_renewable_remainder, self.auto_renewable, self.family_auto_renewable)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/account/user_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class UserSettings(YandexMusicObject):
show_disk_tracks_in_library: Optional[bool] = None
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (
self.uid,
self.last_fm_scrobbling_enabled,
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/album/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Album(YandexMusicObject):
available_for_options: Optional[List[str]] = None
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.id,)

def with_tracks(self, *args, **kwargs) -> Optional['Album']:
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/album/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Deprecation(YandexMusicObject):
done: Optional[bool]
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.target_album_id, self.status, self.done)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/album/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Label(YandexMusicObject):
name: str
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.id, self.name)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/album/track_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TrackPosition(YandexMusicObject):
index: int
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.volume, self.index)

@classmethod
Expand Down
14 changes: 9 additions & 5 deletions yandex_music/artist/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Artist(YandexMusicObject):
ya_money_id: Optional[str] = None
client: 'Client' = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.id, self.name, self.cover)

def get_op_image_url(self, size: str = '200x200') -> str:
Expand Down Expand Up @@ -223,28 +223,32 @@ async def dislike_async(self, *args, **kwargs) -> bool:
"""
return await self.client.users_likes_artists_remove(self.id, self.client.me.account.uid, *args, **kwargs)

def get_tracks(self, page=0, page_size=20, *args, **kwargs) -> Optional['ArtistTracks']:
def get_tracks(self, page: int = 0, page_size: int = 20, *args, **kwargs) -> Optional['ArtistTracks']:
"""Сокращение для::

client.artists_tracks(artist.id, page, page_size, *args, **kwargs)
"""
return self.client.artists_tracks(self.id, page, page_size, *args, **kwargs)

async def get_tracks_async(self, page=0, page_size=20, *args, **kwargs) -> Optional['ArtistTracks']:
async def get_tracks_async(self, page: int = 0, page_size: int = 20, *args, **kwargs) -> Optional['ArtistTracks']:
"""Сокращение для::

await client.artists_tracks(artist.id, page, page_size, *args, **kwargs)
"""
return await self.client.artists_tracks(self.id, page, page_size, *args, **kwargs)

def get_albums(self, page=0, page_size=20, sort_by='year', *args, **kwargs) -> Optional['ArtistAlbums']:
def get_albums(
self, page: int = 0, page_size: int = 20, sort_by: str = 'year', *args, **kwargs
) -> Optional['ArtistAlbums']:
"""Сокращение для::

client.artists_direct_albums(artist.id, page, page_size, sort_by, *args, **kwargs)
"""
return self.client.artists_direct_albums(self.id, page, page_size, sort_by, *args, **kwargs)

async def get_albums_async(self, page=0, page_size=20, sort_by='year', *args, **kwargs) -> Optional['ArtistAlbums']:
async def get_albums_async(
self, page: int = 0, page_size: int = 20, sort_by: str = 'year', *args, **kwargs
) -> Optional['ArtistAlbums']:
"""Сокращение для::

await client.artists_direct_albums(artist.id, page, page_size, sort_by, *args, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions yandex_music/artist/artist_albums.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class ArtistAlbums(YandexMusicObject):
pager: Optional['Pager']
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.pager, self.albums)

def __getitem__(self, item) -> 'Album':
def __getitem__(self, item: int) -> 'Album':
return self.albums[item]

def __iter__(self) -> Iterator['Album']:
Expand Down
4 changes: 2 additions & 2 deletions yandex_music/artist/artist_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class ArtistTracks(YandexMusicObject):
pager: Optional['Pager']
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.pager, self.tracks)

def __getitem__(self, item) -> 'Track':
def __getitem__(self, item: int) -> 'Track':
return self.tracks[item]

def __iter__(self) -> Iterator['Track']:
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/artist/brief_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BriefInfo(YandexMusicObject):
tracks_in_chart: List['Chart'] = None
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (
self.artist,
self.albums,
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/artist/counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Counts(YandexMusicObject):
also_tracks: int
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.tracks, self.direct_albums, self.also_albums, self.also_tracks)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/artist/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Description(YandexMusicObject):
uri: str
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.text, self.uri)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/artist/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Link(YandexMusicObject):
social_network: Optional[str] = None
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.title, self.href, self.type)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/artist/ratings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Ratings(YandexMusicObject):
day: Optional[int] = None
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (self.week, self.month)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion yandex_music/artist/vinyl.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Vinyl(YandexMusicObject):
picture: Optional[str] = None
client: Optional['Client'] = None

def __post_init__(self):
def __post_init__(self) -> None:
self._id_attrs = (
self.title,
self.price,
Expand Down
Loading