From 07b30cb0b909289802fe3e6785f6204c4b8b76eb Mon Sep 17 00:00:00 2001 From: Ilya Siamionau Date: Fri, 17 Nov 2023 22:10:37 +0100 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B5=D0=B7=D0=B4=20?= =?UTF-8?q?=D0=BD=D0=B0=20ruff=20=D0=B8=20ruff=20format=20(#625)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/black.yml | 25 ------- .github/workflows/ruff.yml | 29 ++++++++ CONTRIBUTING.md | 14 ++-- Makefile | 16 ++-- black.toml | 21 ------ docs/source/conf.py | 2 +- examples/chart.py | 1 - examples/daily_playlist_updater.py | 5 +- examples/like_and_dislike.py | 1 - examples/lyrics_playing_track.py | 1 - examples/player.py | 14 ++-- examples/proxy.py | 2 +- examples/radio_example/radio.py | 7 +- examples/radio_example/radio_example.py | 4 +- examples/radio_example/stream_example.py | 4 +- examples/search.py | 5 +- generate_async_version.py | 11 +-- generate_camel_case_aliases.py | 18 ++--- requirements-dev.txt | 2 +- ruff.toml | 54 ++++++++++++++ setup.py | 16 ++-- tests/__init__.py | 59 +++++++-------- tests/conftest.py | 72 +++++++++--------- tests/test_album.py | 4 +- tests/test_chart_info.py | 2 +- tests/test_chart_info_menu.py | 2 +- tests/test_chart_info_menu_item.py | 2 +- tests/test_cover.py | 2 +- tests/test_custom_wave.py | 2 - tests/test_genre.py | 2 +- tests/test_images.py | 2 +- tests/test_label.py | 2 +- tests/test_lyrics.py | 22 +++--- tests/test_meta_data.py | 2 +- tests/test_mix_link.py | 2 +- tests/test_playlist.py | 2 +- tests/test_r128.py | 2 - tests/test_station_data.py | 2 +- tests/test_station_tracks_result.py | 2 +- tests/test_suggestions.py | 3 +- yandex_music/__init__.py | 1 + yandex_music/account/account.py | 5 +- yandex_music/account/alert.py | 2 +- yandex_music/account/auto_renewable.py | 2 +- yandex_music/account/deactivation.py | 2 +- yandex_music/account/operator.py | 2 +- yandex_music/account/passport_phone.py | 2 +- yandex_music/account/permissions.py | 2 +- yandex_music/account/product.py | 4 +- yandex_music/account/status.py | 4 +- yandex_music/account/subscription.py | 6 +- yandex_music/album/album.py | 6 +- yandex_music/album/label.py | 4 +- yandex_music/artist/artist.py | 8 +- yandex_music/artist/artist_albums.py | 4 +- yandex_music/artist/artist_tracks.py | 6 +- yandex_music/artist/brief_info.py | 6 +- yandex_music/artist/link.py | 4 +- yandex_music/artist/vinyl.py | 4 +- yandex_music/base.py | 15 ++-- yandex_music/client.py | 30 ++++---- yandex_music/client_async.py | 30 ++++---- yandex_music/cover.py | 4 +- yandex_music/download_info.py | 20 ++--- yandex_music/experiments.py | 1 - yandex_music/feed/album_event.py | 6 +- yandex_music/feed/artist_event.py | 6 +- yandex_music/feed/day.py | 4 +- yandex_music/feed/event.py | 8 +- yandex_music/feed/feed.py | 6 +- yandex_music/feed/generated_playlist.py | 2 +- yandex_music/feed/track_with_ads.py | 4 +- yandex_music/genre/genre.py | 6 +- yandex_music/genre/title.py | 4 +- yandex_music/landing/block.py | 8 +- yandex_music/landing/block_entity.py | 14 ++-- yandex_music/landing/chart.py | 2 +- yandex_music/landing/chart_info.py | 2 +- yandex_music/landing/chart_info_menu.py | 2 +- yandex_music/landing/chart_info_menu_item.py | 2 +- yandex_music/landing/chart_item.py | 6 +- yandex_music/landing/landing.py | 4 +- yandex_music/landing/landing_list.py | 4 +- yandex_music/landing/mix_link.py | 6 +- yandex_music/landing/play_context.py | 2 +- yandex_music/landing/play_contexts_data.py | 2 +- yandex_music/landing/promotion.py | 4 +- yandex_music/landing/track_id.py | 3 +- yandex_music/landing/track_short_old.py | 4 +- yandex_music/like.py | 4 +- yandex_music/permission_alerts.py | 2 +- yandex_music/playlist/brand.py | 2 +- yandex_music/playlist/custom_wave.py | 2 +- yandex_music/playlist/made_for.py | 4 +- yandex_music/playlist/playlist.py | 46 ++++++------ yandex_music/playlist/playlist_id.py | 4 +- .../playlist/playlist_recommendation.py | 2 +- yandex_music/playlist/tag_result.py | 4 +- yandex_music/playlist/user.py | 2 +- yandex_music/queue/queue.py | 6 +- yandex_music/queue/queue_item.py | 2 +- yandex_music/rotor/dashboard.py | 2 +- yandex_music/rotor/enum.py | 2 +- yandex_music/rotor/restrictions.py | 2 +- yandex_music/rotor/sequence.py | 4 +- yandex_music/rotor/station.py | 4 +- yandex_music/rotor/station_result.py | 11 +-- yandex_music/rotor/station_tracks_result.py | 2 +- yandex_music/rotor/value.py | 4 +- yandex_music/search/best.py | 2 +- yandex_music/search/search.py | 6 +- yandex_music/search/search_result.py | 4 +- yandex_music/search/suggestions.py | 4 +- yandex_music/settings.py | 6 +- yandex_music/shot/shot.py | 4 +- yandex_music/shot/shot_event.py | 2 +- yandex_music/supplement/supplement.py | 2 +- yandex_music/supplement/video_supplement.py | 4 +- yandex_music/track/licence_text_part.py | 4 +- yandex_music/track/lyrics_major.py | 1 - yandex_music/track/poetry_lover_match.py | 2 +- yandex_music/track/track.py | 28 +++---- yandex_music/track/track_lyrics.py | 1 - yandex_music/track/tracks_similar.py | 2 +- yandex_music/track_short.py | 8 +- yandex_music/tracks_list.py | 6 +- yandex_music/utils/request.py | 69 ++++++++---------- yandex_music/utils/request_async.py | 73 +++++++++---------- yandex_music/utils/sign_request.py | 9 +-- yandex_music/video.py | 4 +- 130 files changed, 538 insertions(+), 539 deletions(-) delete mode 100644 .github/workflows/black.yml create mode 100644 .github/workflows/ruff.yml delete mode 100644 black.toml create mode 100644 ruff.toml diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml deleted file mode 100644 index f74ee556..00000000 --- a/.github/workflows/black.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Black - -on: [ pull_request ] - -jobs: - black: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository. - uses: actions/checkout@v4 - - - name: Setup Python. - uses: actions/setup-python@v4 - with: - python-version: 3.7 - - - name: Install dependencies. - run: pip install black - - - name: Check code style of tests. - run: black --config=black.toml --check tests - - - name: Check code style of package. - run: black --config=black.toml --check yandex_music diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml new file mode 100644 index 00000000..6aaa5d5e --- /dev/null +++ b/.github/workflows/ruff.yml @@ -0,0 +1,29 @@ +name: Linter and code style check + +on: [ pull_request ] + +permissions: + contents: read + +jobs: + ruff: + runs-on: ubuntu-latest + steps: + - name: Checkout repository. + uses: actions/checkout@v4 + + - name: Setup Python. + uses: actions/setup-python@v4 + with: + python-version: 3.7 + + - name: Run linter check. + uses: chartboost/ruff-action@v1 + with: + version: 0.1.6 + + - name: Run code style check. + uses: chartboost/ruff-action@v1 + with: + version: 0.1.6 + args: format --check diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 22343c9a..4f85d236 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,17 +39,17 @@ PR'ы должны быть сделаны в `main` ветку. Определ ## Форматирование кода (стиль написания) -В проекте используется `black`. Не забывайте перед публикацией отформатировать код и проверить его на работоспособность. Используются одинарные кавычки. Запускайте `black` с конфигом из основной директории: +В проекте используется `ruff`. Не забывайте перед публикацией отформатировать код и проверить его на работоспособность. Используются одинарные кавычки. +Запуск линтера: ```shell -black --config=black.toml yandex_music +ruff . ``` -или - +Запуск форматера: ```shell -make black -``` +ruff format . +```` ## Создание новых моделей @@ -94,4 +94,4 @@ _Используйте WSL если вы на Windows._ make all ``` -Выполнит за вас black для основного модуля и тестов, сгенерирует асинхронную версию клиента, сгенерирует camel case псевдонимы. +Выполнит за вас ruff и ruff format, сгенерирует асинхронную версию клиента, сгенерирует camel case псевдонимы. diff --git a/Makefile b/Makefile index 22fc1f80..3463ed95 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ # makefile for Yandex Music project -black: - black --config=black.toml yandex_music +ruff: + ruff . --fix -black_test: - black --config=black.toml tests +ruff_format: + ruff format . gen_async: python generate_async_version.py @@ -15,17 +15,11 @@ gen_alias: gen: make gen_async && make gen_alias -b: - make black - -bt: - make black_test - g: make gen all: - make g && make b && make bt + make g && make ruff && make ruff_format a: make all diff --git a/black.toml b/black.toml deleted file mode 100644 index 7f8e388e..00000000 --- a/black.toml +++ /dev/null @@ -1,21 +0,0 @@ -[tool.black] -line-length = 120 -skip-string-normalization=true -target-version = ['py37'] -include = '\.pyi?$' -exclude = ''' -( - /( - \.eggs - | \.git - | \.hg - | \.mypy_cache - | \.tox - | \.venv - | _build - | buck-out - | build - | dist - )/ -) -''' \ No newline at end of file diff --git a/docs/source/conf.py b/docs/source/conf.py index 53a4fa4d..314eddac 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -49,7 +49,7 @@ myst_heading_anchors = 4 # https://myst-parser.readthedocs.io/en/latest/syntax/optional.html?highlight=header-anchors#code-fences-using-colons -myst_enable_extensions = ["colon_fence"] +myst_enable_extensions = ['colon_fence'] # TODO add substitution https://myst-parser.readthedocs.io/en/latest/syntax/optional.html?highlight=header-anchors#substitutions-with-jinja2 # -- Options for HTML output ------------------------------------------------- diff --git a/examples/chart.py b/examples/chart.py index dfb390d2..14898cff 100644 --- a/examples/chart.py +++ b/examples/chart.py @@ -2,7 +2,6 @@ from yandex_music import Client - CHART_ID = 'world' TOKEN = os.environ.get('TOKEN') diff --git a/examples/daily_playlist_updater.py b/examples/daily_playlist_updater.py index bfa72e33..f2a0a53d 100644 --- a/examples/daily_playlist_updater.py +++ b/examples/daily_playlist_updater.py @@ -1,5 +1,6 @@ -import sys import datetime +import sys + from yandex_music.client import Client # Help text @@ -19,7 +20,7 @@ # Check if we don't need to update it if DailyPlaylist.play_counter.updated: - modifiedDate = datetime.datetime.strptime(DailyPlaylist.modified, "%Y-%m-%dT%H:%M:%S%z").date() + modifiedDate = datetime.datetime.strptime(DailyPlaylist.modified, '%Y-%m-%dT%H:%M:%S%z').date() if datetime.datetime.now().date() == modifiedDate: print('\x1b[6;30;43m' + 'Looks like it has been already updated today' + '\x1b[0m') quit() diff --git a/examples/like_and_dislike.py b/examples/like_and_dislike.py index 25fffdea..3f959906 100644 --- a/examples/like_and_dislike.py +++ b/examples/like_and_dislike.py @@ -2,7 +2,6 @@ from yandex_music import Client - TOKEN = os.environ.get('TOKEN') ALBUM_ID = 2832563 diff --git a/examples/lyrics_playing_track.py b/examples/lyrics_playing_track.py index 256f8b87..993d0559 100644 --- a/examples/lyrics_playing_track.py +++ b/examples/lyrics_playing_track.py @@ -3,7 +3,6 @@ from yandex_music import Client from yandex_music.exceptions import NotFoundError - TOKEN = os.environ.get('TOKEN') client = Client(TOKEN).init() diff --git a/examples/player.py b/examples/player.py index a32fcb2b..08e7fe20 100644 --- a/examples/player.py +++ b/examples/player.py @@ -1,10 +1,10 @@ #!/usr/bin/env python3 -import sys import argparse import re -from time import sleep -from subprocess import call +import sys from pathlib import Path +from subprocess import call +from time import sleep from typing import List from yandex_music import Client @@ -22,7 +22,7 @@ parser.add_argument( '--token', default=DEFAULT_CACHE_FOLDER / CONFIG_NAME, help='YM API token as string or path to file' ) -parser.add_argument('--no-save-token', action='store_true', help='do\'nt save token in cache folder') +parser.add_argument('--no-save-token', action='store_true', help="do'nt save token in cache folder") parser.add_argument('--cache-folder', type=Path, default=DEFAULT_CACHE_FOLDER, help='cached tracks folder') parser.add_argument('--audio-player', default='cvlc', help='player to use') parser.add_argument( @@ -43,7 +43,7 @@ print(args) sys.exit() -if type(args.token) is str and re.match(r'^[A-Za-z0-9]{39}$', args.token): +if isinstance(args.token, str) and re.match(r'^[A-Za-z0-9]{39}$', args.token): if not args.no_save_token: parser.get_default('token').write_text(args.token) else: @@ -62,7 +62,7 @@ if args.playlist == 'user': user_playlists = client.users_playlists_list() if not args.playlist_name: - print('specify --playlist-name', list(p.title for p in user_playlists)) + print('specify --playlist-name', [p.title for p in user_playlists]) sys.exit(1) playlist = next((p for p in user_playlists if p.title == args.playlist_name), None) if playlist is None: @@ -82,7 +82,7 @@ shuffle(tracks.tracks) error_count = 0 -for (i, short_track) in enumerate(tracks): +for i, short_track in enumerate(tracks): if args.skip and args.skip > i: continue diff --git a/examples/proxy.py b/examples/proxy.py index b00237c8..d1a72d7c 100644 --- a/examples/proxy.py +++ b/examples/proxy.py @@ -9,7 +9,7 @@ try: if not yandex_music_token: - raise YandexMusicError() + raise YandexMusicError # подключаемся без прокси для получения информации об аккаунте (доступно из других стран) client = Client(yandex_music_token, request=Request()).init() diff --git a/examples/radio_example/radio.py b/examples/radio_example/radio.py index 9f8b44bd..b6b9eb2e 100644 --- a/examples/radio_example/radio.py +++ b/examples/radio_example/radio.py @@ -60,7 +60,7 @@ def __send_start_radio(self, batch_id): def __send_play_start_track(self, track, play_id): total_seconds = track.duration_ms / 1000 self.client.play_audio( - from_="desktop_win-home-playlist_of_the_day-playlist-default", + from_='desktop_win-home-playlist_of_the_day-playlist-default', track_id=track.id, album_id=track.albums[0].id, play_id=play_id, @@ -77,7 +77,7 @@ def __send_play_end_track(self, track, play_id): played_seconds = track.duration_ms / 1000 total_seconds = track.duration_ms / 1000 self.client.play_audio( - from_="desktop_win-home-playlist_of_the_day-playlist-default", + from_='desktop_win-home-playlist_of_the_day-playlist-default', track_id=track.id, album_id=track.albums[0].id, play_id=play_id, @@ -91,8 +91,7 @@ def __send_play_end_radio(self, track, batch_id): self.client.rotor_station_feedback_track_finished( station=self.station_id, track_id=track.id, total_played_seconds=played_seconds, batch_id=batch_id ) - pass @staticmethod def __generate_play_id(): - return "%s-%s-%s" % (int(random() * 1000), int(random() * 1000), int(random() * 1000)) + return '%s-%s-%s' % (int(random() * 1000), int(random() * 1000), int(random() * 1000)) diff --git a/examples/radio_example/radio_example.py b/examples/radio_example/radio_example.py index a6fe7082..51eb2d9d 100644 --- a/examples/radio_example/radio_example.py +++ b/examples/radio_example/radio_example.py @@ -2,10 +2,10 @@ from random import random from time import sleep -from yandex_music import Client - from radio import Radio +from yandex_music import Client + # API instance client = Client(token='YOUR_TOKEN_HERE') diff --git a/examples/radio_example/stream_example.py b/examples/radio_example/stream_example.py index 8153ce0b..b5d003fd 100644 --- a/examples/radio_example/stream_example.py +++ b/examples/radio_example/stream_example.py @@ -1,9 +1,9 @@ from time import sleep -from yandex_music import Client - from radio import Radio +from yandex_music import Client + # API instance client = Client(token='YOUR_API_KEY_HERE').init() diff --git a/examples/search.py b/examples/search.py index 8670dc21..bcc0cce6 100644 --- a/examples/search.py +++ b/examples/search.py @@ -1,6 +1,5 @@ from yandex_music import Client - client = Client().init() type_to_name = { @@ -15,7 +14,7 @@ } -def send_search_request_and_print_result(query): +def send_search_request_and_print_result(query): # noqa: C901 search_result = client.search(query) text = [f'Результаты по запросу "{query}":', ''] @@ -35,7 +34,7 @@ def send_search_request_and_print_result(query): elif type_ == 'artist': best_result_text = best.name elif type_ in ['album', 'podcast']: - best_result_text = best.title + best_result_text = best.title # noqa: SIM114 elif type_ == 'playlist': best_result_text = best.title elif type_ == 'video': diff --git a/generate_async_version.py b/generate_async_version.py index 3b4aad96..e2c5a2fa 100755 --- a/generate_async_version.py +++ b/generate_async_version.py @@ -1,8 +1,7 @@ #!/usr/bin/env python3 import subprocess - -DISCLAIMER = '# THIS IS AUTO GENERATED COPY OF client.py. DON\'T EDIT IN BY HANDS #' +DISCLAIMER = "# THIS IS AUTO GENERATED COPY OF client.py. DON'T EDIT IN BY HANDS #" DISCLAIMER = f'{"#" * len(DISCLAIMER)}\n{DISCLAIMER}\n{"#" * len(DISCLAIMER)}\n\n' REQUEST_METHODS = ('_request_wrapper', 'get', 'post', 'retrieve', 'download') @@ -18,7 +17,7 @@ def gen_request(output_request_filename): code = code.replace('resp.content', 'content') code = code.replace( 'resp = requests.request(*args, **kwargs)', - f'async with aiohttp.request(*args, **kwargs) as _resp:\n{" " * 16}resp = _resp\n{" " * 16}content = await resp.content.read()', + f'async with aiohttp.request(*args, **kwargs) as _resp:\n{" " * 16}resp = _resp\n{" " * 16}content = await resp.content.read()', # noqa: E501 ) code = code.replace('except requests.Timeout', 'except asyncio.TimeoutError') @@ -32,7 +31,7 @@ def gen_request(output_request_filename): code = code.replace('proxies=self.proxies', 'proxy=self.proxy_url') code = code.replace( "kwargs['timeout'] = self._timeout", - f"kwargs['timeout'] = aiohttp.ClientTimeout(total=self._timeout)\n{' ' * 8}else:\n{' ' * 12}kwargs['timeout'] = aiohttp.ClientTimeout(total=kwargs['timeout'])", + f"kwargs['timeout'] = aiohttp.ClientTimeout(total=self._timeout)\n{' ' * 8}else:\n{' ' * 12}kwargs['timeout'] = aiohttp.ClientTimeout(total=kwargs['timeout'])", # noqa: E501 ) # download method @@ -85,4 +84,6 @@ def gen_client(output_client_filename): gen_client(client_filename) for file in (request_filename, client_filename): - subprocess.run(['black', '--config', 'black.toml', file]) + subprocess.run(['ruff', 'format', '--quiet', file]) # noqa: S603, S607 + subprocess.run(['ruff', '--quiet', '--fix', file]) # noqa: S603, S607 + subprocess.run(['ruff', 'format', '--quiet', file]) # noqa: S603, S607 diff --git a/generate_camel_case_aliases.py b/generate_camel_case_aliases.py index ef425415..b973d0c6 100755 --- a/generate_camel_case_aliases.py +++ b/generate_camel_case_aliases.py @@ -1,14 +1,14 @@ #!/usr/bin/env python3 -import os import ast +import os SOURCE_FOLDER = 'yandex_music' EXCLUDED_FUNCTIONS = {'de_dict', 'de_json', 'de_list', 'de_json_async', 'de_list_async'} -ALIAS_TEMPLATE = ''' +ALIAS_TEMPLATE = """ #: Псевдоним для :attr:`{name}` {camel_case_name} = {name} -''' +""" ALIAS_SECTION_MARKER = ' # camelCase псевдонимы' @@ -38,9 +38,8 @@ def _generate_code(function_name: str, intent=0) -> str: code_lines = [line for line in code.split('\n') if line] code_lines = [f'{" " * intent}{line}' for line in code_lines] - code = '\n'.join(code_lines) - return code + return '\n'.join(code_lines) def _process_file(file: str) -> None: @@ -52,10 +51,9 @@ def _process_file(file: str) -> None: if isinstance(node, ast.ClassDef): count_of_class_def += 1 - if isinstance(node, ast.FunctionDef) or isinstance(node, ast.AsyncFunctionDef): - if _validate_function_name(node.name): - alias_code = _generate_code(node.name, node.col_offset) - file_aliases_code_fragments.append(alias_code) + if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and _validate_function_name(node.name): + alias_code = _generate_code(node.name, node.col_offset) + file_aliases_code_fragments.append(alias_code) # there are no such cases in data models yet # only in yandex_music/exceptions.py and yandex_music/utils/difference.py @@ -76,7 +74,7 @@ def _process_file(file: str) -> None: return # remove prev aliases - file_code_lines = file_code_lines[:marker_lineno + 1] + file_code_lines = file_code_lines[: marker_lineno + 1] file_code_lines.append('') file_code_lines.extend(file_aliases_code_fragments) file_code_lines.append('') diff --git a/requirements-dev.txt b/requirements-dev.txt index 726b20bc..bbdcd15d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,7 +3,7 @@ requests aiohttp aiofiles # rly dev -black +ruff==0.1.6 coverage pytest pytest-cov diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 00000000..550ee52f --- /dev/null +++ b/ruff.toml @@ -0,0 +1,54 @@ +extend-select = [ + "E", # pycodestyle errors + "W", # pycodestyle warnings + "F", # Pyflakes + "I", # isort + "C90", # flake8-comprehensions + "B", # flake8-bugbear + "Q", # flake8-quotes + "S", # flake8-bandit + "ASYNC", # flake8-async + # "ANN", # flake8-annotations. Not all resolved yet + "C", + "BLE", + "ERA", + "ICN", + "INP", + "ISC", + "NPY", + "PGH", + "PIE", + "RET", + "RSE", + "SIM", + "T20", + "TCH", + "TID", + "YTT", +] +line-length = 120 +target-version = "py37" +ignore = [ + "PGH004", # use specific rule code with noqa; works bad with JetBrains IDE Warnings + "ANN002", # Missing type annotation for `*args` + "ANN003", # Missing type annotation for `**kwargs` + "ANN101", # Missing type annotation for `self` in method + "ANN102", # Missing type annotation for `cls` in classmethod +] + +[per-file-ignores] +"examples/*.py" = ["T201", "S311", "ERA001", "INP001", "S106", "BLE001", "S603"] +"docs/source/conf.py" = ["INP001"] +"tests/*.py" = ["S101"] # 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"] + +[flake8-quotes] +docstring-quotes = "double" +multiline-quotes = "double" +inline-quotes = "single" + +[format] +quote-style = "single" diff --git a/setup.py b/setup.py index 4a728e1f..5fbec79c 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ import re import sys -from setuptools import setup, find_packages +from setuptools import find_packages, setup from setuptools.command.test import test @@ -41,20 +41,20 @@ def run_tests(self): 'Operating System :: OS Independent', 'Topic :: Internet', 'Topic :: Multimedia :: Sound/Audio', - "Topic :: Software Development :: Libraries", - "Topic :: Software Development :: Libraries :: Python Modules", - "Topic :: Software Development :: Libraries :: Application Frameworks", + 'Topic :: Software Development :: Libraries', + 'Topic :: Software Development :: Libraries :: Python Modules', + 'Topic :: Software Development :: Libraries :: Application Frameworks', 'Programming Language :: Python', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', - "Programming Language :: Python :: Implementation", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", + 'Programming Language :: Python :: Implementation', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', ], - python_requires="~=3.7", + python_requires='~=3.7', cmdclass={'test': PyTest}, tests_require=['pytest'], project_urls={ diff --git a/tests/__init__.py b/tests/__init__.py index b7f60fd7..d9e087d7 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,24 +2,32 @@ from .test_ad_params import TestAdParams from .test_album import TestAlbum from .test_album_event import TestAlbumEvent +from .test_alert import TestAlert +from .test_alert_button import TestAlertButton from .test_artist import TestArtist from .test_artist_event import TestArtistEvent from .test_auto_renewable import TestAutoRenewable from .test_best import TestBest from .test_block import TestBlock from .test_block_entity import TestBlockEntity +from .test_brand import TestBrand from .test_case_forms import TestCaseForms from .test_chart import TestChart +from .test_chart_info import TestChartInfo +from .test_chart_info_menu import TestChartInfoMenu +from .test_chart_info_menu_item import TestChartInfoMenuItem +from .test_contest import TestContest +from .test_context import TestContext from .test_counts import TestCounts from .test_cover import TestCover +from .test_custom_wave import TestCustomWave from .test_day import TestDay +from .test_deactivation import TestDeactivation +from .test_deprecation import TestDeprecation from .test_description import TestDescription from .test_discrete_scale import TestDiscreteScale from .test_enum import TestEnum from .test_event import TestEvent -from .test_chart_info_menu_item import TestChartInfoMenuItem -from .test_chart_info_menu import TestChartInfoMenu -from .test_chart_info import TestChartInfo from .test_generated_playlist import TestGeneratedPlaylist from .test_genre import TestGenre from .test_icon import TestIcon @@ -27,13 +35,19 @@ from .test_images import TestImages from .test_invocation_info import TestInvocationInfo from .test_label import TestLabel -from .test_link import TestLink +from .test_licence_text_part import TestLicenceTextPart from .test_link import TestLink from .test_lyrics import TestLyrics +from .test_lyrics_info import TestLyricsInfo +from .test_lyrics_major import TestLyricsMajor from .test_made_for import TestMadeFor from .test_major import TestMajor +from .test_meta_data import TestMetaData from .test_mix_link import TestMixLink +from .test_non_auto_renewable import TestNonAutoRenewable from .test_normalization import TestNormalization +from .test_open_graph_data import TestOpenGraphData +from .test_operator import TestOperator from .test_pager import TestPager from .test_passport_phone import TestPassportPhone from .test_permissions import TestPermissions @@ -44,57 +58,40 @@ from .test_playlist import TestPlaylist from .test_playlist_absence import TestPlaylistAbsence from .test_playlist_id import TestPlaylistId -from .test_playlist_id import TestPlaylistId from .test_plus import TestPlus +from .test_poetry_lover_match import TestPoetryLoverMatch from .test_price import TestPrice from .test_product import TestProduct from .test_promotion import TestPromotion +from .test_queue_item import TestQueueItem +from .test_r128 import TestR128 from .test_ratings import TestRatings +from .test_renewable_remainder import TestRenewableRemainder from .test_restrictions import TestRestrictions from .test_rotor_settings import TestRotorSettings from .test_search_result import TestSearchResult from .test_sequence import TestSequence from .test_settings import TestSettings +from .test_shot import TestShot +from .test_shot_data import TestShotData +from .test_shot_type import TestShotType from .test_station import TestStation +from .test_station_data import TestStationData from .test_station_result import TestStationResult from .test_status import TestStatus from .test_subscription import TestSubscription from .test_suggestions import TestSuggestions +from .test_tag import TestTag from .test_title import TestTitle from .test_track import TestTrack from .test_track_id import TestTrackId +from .test_track_lyrics import TestTrackLyrics from .test_track_position import TestTrackPosition from .test_track_short import TestTrackShort from .test_track_short_old import TestTrackShortOld from .test_track_with_ads import TestTrackWithAds from .test_user import TestUser from .test_value import TestValue -from .test_value import TestValue from .test_video import TestVideo from .test_video_supplement import TestVideoSupplement from .test_vinyl import TestVinyl -from .test_shot_type import TestShotType -from .test_shot_data import TestShotData -from .test_shot import TestShot -from .test_renewable_remainder import TestRenewableRemainder -from .test_tag import TestTag -from .test_meta_data import TestMetaData -from .test_licence_text_part import TestLicenceTextPart -from .test_station_data import TestStationData -from .test_alert_button import TestAlertButton -from .test_alert import TestAlert -from .test_non_auto_renewable import TestNonAutoRenewable -from .test_poetry_lover_match import TestPoetryLoverMatch -from .test_deactivation import TestDeactivation -from .test_operator import TestOperator -from .test_contest import TestContest -from .test_open_graph_data import TestOpenGraphData -from .test_brand import TestBrand -from .test_context import TestContext -from .test_queue_item import TestQueueItem -from .test_deprecation import TestDeprecation -from .test_lyrics_major import TestLyricsMajor -from .test_track_lyrics import TestTrackLyrics -from .test_custom_wave import TestCustomWave -from .test_r128 import TestR128 -from .test_lyrics_info import TestLyricsInfo diff --git a/tests/conftest.py b/tests/conftest.py index 2ec8d935..028667f6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,16 +1,20 @@ import pytest from yandex_music import ( + R128, Account, AdParams, Album, AlbumEvent, + Alert, + AlertButton, Artist, ArtistEvent, AutoRenewable, Best, Block, BlockEntity, + Brand, CaseForms, Chart, ChartInfo, @@ -18,10 +22,14 @@ ChartInfoMenuItem, ChartItem, Client, + Contest, + Context, Counts, Cover, CustomWave, Day, + Deactivation, + Deprecation, Description, DiscreteScale, Enum, @@ -35,11 +43,16 @@ LicenceTextPart, Link, Lyrics, + LyricsInfo, + LyricsMajor, MadeFor, Major, MetaData, MixLink, + NonAutoRenewable, Normalization, + OpenGraphData, + Operator, Pager, PassportPhone, Permissions, @@ -51,6 +64,7 @@ PlaylistAbsence, PlaylistId, Plus, + PoetryLoverMatch, Price, Product, Promotion, @@ -65,6 +79,7 @@ ShotData, ShotType, Station, + StationData, StationResult, Status, Subscription, @@ -72,6 +87,7 @@ Title, Track, TrackId, + TrackLyrics, TrackPosition, TrackShort, TrackShortOld, @@ -81,40 +97,33 @@ Video, VideoSupplement, Vinyl, - StationData, - AlertButton, - Alert, - NonAutoRenewable, - PoetryLoverMatch, - Deactivation, - Operator, - Contest, - OpenGraphData, - Brand, - Context, - Deprecation, - TrackLyrics, - LyricsMajor, - R128, - LyricsInfo, ) + from . import ( TestAccount, TestAdParams, TestAlbum, + TestAlert, + TestAlertButton, TestArtist, + TestArtistEvent, TestAutoRenewable, TestBest, TestBlock, TestBlockEntity, + TestBrand, TestCaseForms, TestChart, TestChartInfo, TestChartInfoMenuItem, + TestContest, + TestContext, TestCounts, TestCover, TestCustomWave, TestDay, + TestDeactivation, + TestDeprecation, TestDescription, TestDiscreteScale, TestEnum, @@ -128,10 +137,15 @@ TestLicenceTextPart, TestLink, TestLyrics, + TestLyricsInfo, + TestLyricsMajor, TestMajor, TestMetaData, TestMixLink, + TestNonAutoRenewable, TestNormalization, + TestOpenGraphData, + TestOperator, TestPager, TestPassportPhone, TestPermissions, @@ -142,9 +156,11 @@ TestPlaylistAbsence, TestPlaylistId, TestPlus, + TestPoetryLoverMatch, TestPrice, TestProduct, TestPromotion, + TestR128, TestRatings, TestRenewableRemainder, TestRotorSettings, @@ -155,6 +171,7 @@ TestShotData, TestShotType, TestStation, + TestStationData, TestStationResult, TestStatus, TestSubscription, @@ -162,6 +179,7 @@ TestTitle, TestTrack, TestTrackId, + TestTrackLyrics, TestTrackPosition, TestTrackShort, TestTrackShortOld, @@ -171,23 +189,6 @@ TestVideo, TestVideoSupplement, TestVinyl, - TestArtistEvent, - TestStationData, - TestAlertButton, - TestAlert, - TestNonAutoRenewable, - TestPoetryLoverMatch, - TestDeactivation, - TestOperator, - TestContest, - TestOpenGraphData, - TestBrand, - TestContext, - TestDeprecation, - TestLyricsMajor, - TestTrackLyrics, - TestR128, - TestLyricsInfo, ) @@ -742,11 +743,6 @@ def playlist_absence(): return PlaylistAbsence(TestPlaylistAbsence.kind, TestPlaylistAbsence.reason) -@pytest.fixture(scope='session') -def results(playlist): - return [playlist] - - @pytest.fixture(scope='session') def context(): return Context(TestContext.type_, TestContext.id_, TestContext.description) diff --git a/tests/test_album.py b/tests/test_album.py index 674bff6b..c0dd98f8 100644 --- a/tests/test_album.py +++ b/tests/test_album.py @@ -112,10 +112,10 @@ def test_de_list_none(self, client): def test_de_json_required(self, client): json_dict = {'id': self.id} - album = Album.de_json(json_dict, client) + Album.de_json(json_dict, client) def test_de_json_all(self, client, artist, label, track_position, track, album_without_nested_albums, deprecation): - labels = [label] if type(label) == str else [label.to_dict()] + labels = [label] if isinstance(label, str) else [label.to_dict()] json_dict = { 'id': self.id, 'error': self.error, diff --git a/tests/test_chart_info.py b/tests/test_chart_info.py index 91808e05..a532122e 100644 --- a/tests/test_chart_info.py +++ b/tests/test_chart_info.py @@ -64,7 +64,7 @@ def test_equality(self, playlist, chart_info_menu): self.id, self.type, self.type_for_from, self.title, self.chart_description, chart_info_menu, playlist ) b = ChartInfo( - "no_id", self.type, self.type_for_from, self.title, self.chart_description, chart_info_menu, playlist + 'no_id', self.type, self.type_for_from, self.title, self.chart_description, chart_info_menu, playlist ) c = ChartInfo( self.id, self.type, self.type_for_from, self.title, self.chart_description, chart_info_menu, playlist diff --git a/tests/test_chart_info_menu.py b/tests/test_chart_info_menu.py index eee86c57..503d6c0f 100644 --- a/tests/test_chart_info_menu.py +++ b/tests/test_chart_info_menu.py @@ -19,7 +19,7 @@ def test_de_json_required(self, chart_info_menu_item, client): def test_equality(self, chart_info_menu_item): a = ChartInfoMenu([chart_info_menu_item]) - b = ChartInfoMenu([ChartInfoMenuItem("tt", "no_url")]) + b = ChartInfoMenu([ChartInfoMenuItem('tt', 'no_url')]) c = ChartInfoMenu([chart_info_menu_item]) assert a != b diff --git a/tests/test_chart_info_menu_item.py b/tests/test_chart_info_menu_item.py index 42407825..6d06a814 100644 --- a/tests/test_chart_info_menu_item.py +++ b/tests/test_chart_info_menu_item.py @@ -40,7 +40,7 @@ def test_de_json_all(self, client): def test_equality(self): a = ChartInfoMenuItem(self.title, self.url, self.selected) - b = ChartInfoMenuItem(self.title, "no_url", self.selected) + b = ChartInfoMenuItem(self.title, 'no_url', self.selected) c = ChartInfoMenuItem(self.title, self.url, self.selected) assert a != b diff --git a/tests/test_cover.py b/tests/test_cover.py index 9c9f9908..32e56bc1 100644 --- a/tests/test_cover.py +++ b/tests/test_cover.py @@ -38,7 +38,7 @@ def test_de_list_none(self, client): def test_de_json_required(self, client): json_dict = {} - cover = Cover.de_json(json_dict, client) + Cover.de_json(json_dict, client) def test_de_json_all(self, client): json_dict = { diff --git a/tests/test_custom_wave.py b/tests/test_custom_wave.py index c52258ce..3758ad1c 100644 --- a/tests/test_custom_wave.py +++ b/tests/test_custom_wave.py @@ -1,5 +1,3 @@ -import pytest - from yandex_music import CustomWave diff --git a/tests/test_genre.py b/tests/test_genre.py index 72081f7b..205f7df0 100644 --- a/tests/test_genre.py +++ b/tests/test_genre.py @@ -53,7 +53,7 @@ def test_expected_values(self, genre, title, images, icon, genre_without_sub_gen assert genre.weight == self.weight assert genre.composer_top == self.composer_top assert genre.title == self.title - assert genre.titles == {"uz": title} + assert genre.titles == {'uz': title} assert genre.images == images assert genre.show_in_menu == self.show_in_menu assert genre.show_in_regions == self.show_in_regions diff --git a/tests/test_images.py b/tests/test_images.py index 320e7d1a..63333613 100644 --- a/tests/test_images.py +++ b/tests/test_images.py @@ -14,7 +14,7 @@ def test_de_json_none(self, client): def test_de_json_required(self, client): json_dict = {} - images = Images.de_json(json_dict, client) + Images.de_json(json_dict, client) def test_de_json_all(self, client): json_dict = {'_208x208': self._208x208, '_300x300': self._300x300} diff --git a/tests/test_label.py b/tests/test_label.py index 84f3c5ab..ff1e40bf 100644 --- a/tests/test_label.py +++ b/tests/test_label.py @@ -8,7 +8,7 @@ class TestLabel: another_representation_of_label = 'NoCopyrightSounds' def test_expected_values(self, label): - if type(label) == str: + if isinstance(label, str): assert label == self.another_representation_of_label else: assert label.id == self.id diff --git a/tests/test_lyrics.py b/tests/test_lyrics.py index 107a0e65..e2d8d43b 100644 --- a/tests/test_lyrics.py +++ b/tests/test_lyrics.py @@ -8,19 +8,19 @@ class TestLyrics: 'Too big, too small?\nSize does matter, after all\nZu groß, zu klein?\nEr könnte etwas größer ' 'sein\n\nMercedes-Benz und Autobahn\nAlleine in das Ausland fahren\nReise, ' 'Reise! Fahrvergnügen\nIch will nur Spaß, mich nicht verlieben\n\nJust a little bit...\nJust a ' - 'little, bitch!\n\nYou\'ve got a pussy\nI have a dick, ah.\nSo what\'s the problem?\nLet\'s do it ' - 'quick!\n\nSo take me now, before it\'s too late\nLife\'s too short, so I can\'t wait\nTake me now! ' - 'Oh, don\'t you see?\nI can\'t get laid in Germany…\n\nToo short, too tall?\nDoesn\'t matter, ' + "little, bitch!\n\nYou've got a pussy\nI have a dick, ah.\nSo what's the problem?\nLet's do it " + "quick!\n\nSo take me now, before it's too late\nLife's too short, so I can't wait\nTake me now! " + "Oh, don't you see?\nI can't get laid in Germany…\n\nToo short, too tall?\nDoesn't matter, " 'one size fits all\nZu groß, zu klein?\nDer Schlagbaum sollte oben sein\n\nSchönes Fräulein, ' 'Lust auf mehr\nBlitzkrieg mit dem Fleischgewehr\nSchnaps im Kopf, du holde Braut\nSteck Bratwurst ' - 'in dein Sauerkraut\n\nJust a little bit...\nBe my little bitch!\n\nYou\'ve got a pussy\nI have a ' - 'dick, ah\nSo what\'s the problem?\nLet\'s do it quick!\n\nSo take me now, before it\'s too ' - 'late\nLife\'s too short, so I can\'t wait\nTake me now! Oh, don\'t you see?\nI can\'t get laid in ' - 'Germany…\n\nGermany! Germany!\n\nYou\'ve got a pussy\nI have a dick, ah\nSo what\'s the ' - 'problem?\nLet\'s do it quick!\n\nYou\'ve got a pussy\nI have a dick, ah\nSo what\'s the ' - 'problem?\nLet\'s do it quick!\n\nYou\'ve got a pussy\nI have a dick, ah\nSo what\'s the ' - 'problem?\nLet\'s do it quick!\n\nSo take me now, before it\'s too late\nLife\'s too short, ' - 'so I can\'t wait\nTake me now! Oh, don\'t you see?\nI can\'t get laid in Germany…\n ' + "in dein Sauerkraut\n\nJust a little bit...\nBe my little bitch!\n\nYou've got a pussy\nI have a " + "dick, ah\nSo what's the problem?\nLet's do it quick!\n\nSo take me now, before it's too " + "late\nLife's too short, so I can't wait\nTake me now! Oh, don't you see?\nI can't get laid in " + "Germany…\n\nGermany! Germany!\n\nYou've got a pussy\nI have a dick, ah\nSo what's the " + "problem?\nLet's do it quick!\n\nYou've got a pussy\nI have a dick, ah\nSo what's the " + "problem?\nLet's do it quick!\n\nYou've got a pussy\nI have a dick, ah\nSo what's the " + "problem?\nLet's do it quick!\n\nSo take me now, before it's too late\nLife's too short, " + "so I can't wait\nTake me now! Oh, don't you see?\nI can't get laid in Germany…\n " ) has_rights = True text_language = 'de' diff --git a/tests/test_meta_data.py b/tests/test_meta_data.py index f7df2667..7879e83b 100644 --- a/tests/test_meta_data.py +++ b/tests/test_meta_data.py @@ -35,7 +35,7 @@ class TestMetaData: 'Можете величать меня исчадьем ада\nМожете линчевать меня, мыча как стадо\nНо на мне нет печати зла, ' 'сгущать не надо\nКраски. Я счастлив, что я не раб мещанских взглядов\nМожете обличать меня, крича с экрана' '\nМожете исключать меня из ваших кланов\nНо вы же сами не без греха. Признай, что я был\nК несчастью таким' - ' же, как ты. Ша!\nМолчать и на пол!\n\nСпасибо Kaas\'у, так что не смейте обвинять меня в плагиате\nВсе' + " же, как ты. Ша!\nМолчать и на пол!\n\nСпасибо Kaas'у, так что не смейте обвинять меня в плагиате\nВсе" ' сейчас на Одноклассниках, ВКонтакте\nНо далеко не все одноклассники в контакте\nПонимаете, о чем идет' ' речь?\nЙее, Оксимирон. В Лондоне наконец-то солнце' ) diff --git a/tests/test_mix_link.py b/tests/test_mix_link.py index 3e1c4340..94a9d557 100644 --- a/tests/test_mix_link.py +++ b/tests/test_mix_link.py @@ -8,7 +8,7 @@ class TestMixLink: text_color = '#6c65a9' background_color = 'transparent' background_image_uri = ( - 'avatars.yandex.net/get-music-misc/28592/mix.5cf0bd5e58ea3a1e70caa07b.' 'background-image.1559281047248/%%' + 'avatars.yandex.net/get-music-misc/28592/mix.5cf0bd5e58ea3a1e70caa07b.background-image.1559281047248/%%' ) cover_white = 'avatars.yandex.net/get-music-misc/28052/mix.5cf0bd5e58ea3a1e70caa07b.cover-white.1559281049219/%%' cover_uri = 'avatars.yandex.net/get-music-misc/34161/mix.57c6d15a2d3213a86ac653d2.cover.1555818786846/%%' diff --git a/tests/test_playlist.py b/tests/test_playlist.py index e2067994..b81bc294 100644 --- a/tests/test_playlist.py +++ b/tests/test_playlist.py @@ -27,7 +27,7 @@ class TestPlaylist: id_for_from = 'playlist_of_the_day' dummy_description = 'Слушайте интересные подкасты, чтобы мы могли узнать вас получше и\\xa0собрать этот плейлист' dummy_page_description = ( - 'Чтобы собрать для вас этот плейлист, мы должны узнать ' 'вас чуточку поближе. Слушайте больше!' + 'Чтобы собрать для вас этот плейлист, мы должны узнать вас чуточку поближе. Слушайте больше!' ) metrika_id = 666666 coauthors = [1130000003905541] diff --git a/tests/test_r128.py b/tests/test_r128.py index f117148d..b2b1d142 100644 --- a/tests/test_r128.py +++ b/tests/test_r128.py @@ -1,5 +1,3 @@ -import pytest - from yandex_music import R128 diff --git a/tests/test_station_data.py b/tests/test_station_data.py index 6444b64d..481c4912 100644 --- a/tests/test_station_data.py +++ b/tests/test_station_data.py @@ -2,7 +2,7 @@ class TestStationData: - name = 'Marshal\'s station' + name = "Marshal's station" def test_expected_values(self, station_data): assert station_data.name == self.name diff --git a/tests/test_station_tracks_result.py b/tests/test_station_tracks_result.py index d436850c..b7679386 100644 --- a/tests/test_station_tracks_result.py +++ b/tests/test_station_tracks_result.py @@ -51,7 +51,7 @@ def test_de_json_all(self, client, id_, sequence): def test_equality(self, id_, sequence): a = StationTracksResult(id_, sequence, self.batch_id, self.pumpkin) - b = StationTracksResult(id_, sequence, "", False) + b = StationTracksResult(id_, sequence, '', False) c = StationTracksResult(id_, sequence, self.batch_id, self.pumpkin) assert a != b diff --git a/tests/test_suggestions.py b/tests/test_suggestions.py index 47ed2c29..8cc8e32a 100644 --- a/tests/test_suggestions.py +++ b/tests/test_suggestions.py @@ -1,8 +1,7 @@ import pytest from tests import TestBest - -from yandex_music import Suggestions, Best +from yandex_music import Best, Suggestions @pytest.fixture(scope='class', params=[1, 2, 3, 4, 5]) diff --git a/yandex_music/__init__.py b/yandex_music/__init__.py index 1311e5b4..50ac960a 100644 --- a/yandex_music/__init__.py +++ b/yandex_music/__init__.py @@ -266,6 +266,7 @@ 'QueueItem', 'Deprecation', 'TrackLyrics', + 'LyricsMajor', 'CustomWave', 'R128', 'LyricsInfo', diff --git a/yandex_music/account/account.py b/yandex_music/account/account.py index d383599e..6d4e8e58 100644 --- a/yandex_music/account/account.py +++ b/yandex_music/account/account.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -26,7 +26,8 @@ class Account(YandexMusicObject): passport_phones (:obj:`list` из :obj:`yandex_music.PassportPhone`): Мобильные номера. registered_at (:obj:`str`, optional): Дата создания учётной записи. has_info_for_app_metrica (:obj:`bool`, optional): Наличие информации для App Metrica. - child (:obj:`bool`): Дочерний / детский аккаунт (скорее детский, позволяет ограничить доступный контент ребенку на Кинопоиске). + child (:obj:`bool`): Дочерний / детский аккаунт (скорее детский, позволяет ограничить + доступный контент ребенку на Кинопоиске). client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. **kwargs: Произвольные ключевые аргументы полученные от API. """ diff --git a/yandex_music/account/alert.py b/yandex_music/account/alert.py index 0faa6fa2..35d37ec3 100644 --- a/yandex_music/account/alert.py +++ b/yandex_music/account/alert.py @@ -4,7 +4,7 @@ from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, AlertButton + from yandex_music import AlertButton, Client @model diff --git a/yandex_music/account/auto_renewable.py b/yandex_music/account/auto_renewable.py index f7a996cd..d6843e1f 100644 --- a/yandex_music/account/auto_renewable.py +++ b/yandex_music/account/auto_renewable.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/account/deactivation.py b/yandex_music/account/deactivation.py index 6070e764..f20e6a23 100644 --- a/yandex_music/account/deactivation.py +++ b/yandex_music/account/deactivation.py @@ -1,4 +1,4 @@ -from typing import List, TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/account/operator.py b/yandex_music/account/operator.py index be98e177..067cc417 100644 --- a/yandex_music/account/operator.py +++ b/yandex_music/account/operator.py @@ -1,4 +1,4 @@ -from typing import List, TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/account/passport_phone.py b/yandex_music/account/passport_phone.py index f9d097cd..346113c7 100644 --- a/yandex_music/account/passport_phone.py +++ b/yandex_music/account/passport_phone.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/account/permissions.py b/yandex_music/account/permissions.py index c57b0978..03831d0e 100644 --- a/yandex_music/account/permissions.py +++ b/yandex_music/account/permissions.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/account/product.py b/yandex_music/account/product.py index d98347bd..a5d98f7c 100644 --- a/yandex_music/account/product.py +++ b/yandex_music/account/product.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -102,7 +102,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Product']: return None data = super(Product, cls).de_json(data, client) - from yandex_music import Price, LicenceTextPart + from yandex_music import LicenceTextPart, Price data['price'] = Price.de_json(data.get('price'), client) data['intro_price'] = Price.de_json(data.get('intro_price'), client) diff --git a/yandex_music/account/status.py b/yandex_music/account/status.py index 14fe6da8..b98291b9 100644 --- a/yandex_music/account/status.py +++ b/yandex_music/account/status.py @@ -4,7 +4,7 @@ from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Account, Permissions, Subscription, Plus, StationData, Alert + from yandex_music import Account, Alert, Client, Permissions, Plus, StationData, Subscription @model @@ -69,7 +69,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Status']: return None data = super(Status, cls).de_json(data, client) - from yandex_music import Account, Permissions, Plus, Subscription, StationData, Alert + from yandex_music import Account, Alert, Permissions, Plus, StationData, Subscription data['account'] = Account.de_json(data.get('account'), client) data['permissions'] = Permissions.de_json(data.get('permissions'), client) diff --git a/yandex_music/account/subscription.py b/yandex_music/account/subscription.py index db2cfb92..22fb68f6 100644 --- a/yandex_music/account/subscription.py +++ b/yandex_music/account/subscription.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, AutoRenewable, RenewableRemainder, NonAutoRenewable, Operator + from yandex_music import AutoRenewable, Client, NonAutoRenewable, Operator, RenewableRemainder @model @@ -53,7 +53,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Subscription']: return None data = super(Subscription, cls).de_json(data, client) - from yandex_music import AutoRenewable, RenewableRemainder, NonAutoRenewable, Operator + from yandex_music import AutoRenewable, NonAutoRenewable, Operator, RenewableRemainder data['auto_renewable'] = AutoRenewable.de_list(data.get('auto_renewable'), client) data['family_auto_renewable'] = AutoRenewable.de_list(data.get('family_auto_renewable'), client) diff --git a/yandex_music/album/album.py b/yandex_music/album/album.py index dbee0467..c5755d45 100644 --- a/yandex_music/album/album.py +++ b/yandex_music/album/album.py @@ -1,10 +1,10 @@ -from typing import Any, TYPE_CHECKING, Optional, List, Union +from typing import TYPE_CHECKING, Any, List, Optional, Union from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Artist, Label, TrackPosition, Track, Deprecation + from yandex_music import Artist, Client, Deprecation, Label, Track, TrackPosition @model @@ -299,7 +299,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Album']: return None data = super(Album, cls).de_json(data, client) - from yandex_music import Artist, Label, TrackPosition, Track, Deprecation + from yandex_music import Artist, Deprecation, Label, Track, TrackPosition data['artists'] = Artist.de_list(data.get('artists'), client) diff --git a/yandex_music/album/label.py b/yandex_music/album/label.py index 88c6b933..5335457f 100644 --- a/yandex_music/album/label.py +++ b/yandex_music/album/label.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List, Union +from typing import TYPE_CHECKING, List, Optional, Union from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -58,7 +58,7 @@ def de_list(cls, data: list, client: 'Client') -> List[Union['Label', str]]: if not cls.is_valid_model_data(data, array=True): return [] - labels = list() + labels = [] for label in data: if isinstance(label, dict): labels.append(cls.de_json(label, client)) diff --git a/yandex_music/artist/artist.py b/yandex_music/artist/artist.py index 3392a6bd..13edb7ff 100644 --- a/yandex_music/artist/artist.py +++ b/yandex_music/artist/artist.py @@ -1,10 +1,10 @@ -from typing import Any, TYPE_CHECKING, Optional, List, Union +from typing import TYPE_CHECKING, Any, List, Optional, Union from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Cover, Ratings, Counts, Link, Track, Description, ArtistTracks, ArtistAlbums + from yandex_music import ArtistAlbums, ArtistTracks, Client, Counts, Cover, Description, Link, Ratings, Track @model @@ -266,7 +266,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Artist']: return None data = super(Artist, cls).de_json(data, client) - from yandex_music import Cover, Ratings, Counts, Link, Track, Description + from yandex_music import Counts, Cover, Description, Link, Ratings, Track data['cover'] = Cover.de_json(data.get('cover'), client) data['ratings'] = Ratings.de_json(data.get('ratings'), client) @@ -297,7 +297,7 @@ def de_list(cls, data: list, client: 'Client') -> List['Artist']: if not cls.is_valid_model_data(data, array=True): return [] - artists = list() + artists = [] for artist in data: artists.append(cls.de_json(artist, client)) diff --git a/yandex_music/artist/artist_albums.py b/yandex_music/artist/artist_albums.py index 91a50d92..fcff24cd 100644 --- a/yandex_music/artist/artist_albums.py +++ b/yandex_music/artist/artist_albums.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List, Iterator +from typing import TYPE_CHECKING, Iterator, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Album, Pager + from yandex_music import Album, Client, Pager @model diff --git a/yandex_music/artist/artist_tracks.py b/yandex_music/artist/artist_tracks.py index 6b8a08b4..87683450 100644 --- a/yandex_music/artist/artist_tracks.py +++ b/yandex_music/artist/artist_tracks.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List, Iterator +from typing import TYPE_CHECKING, Iterator, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Track, Pager + from yandex_music import Client, Pager, Track @model @@ -48,7 +48,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['ArtistTracks']: return None data = super(ArtistTracks, cls).de_json(data, client) - from yandex_music import Track, Pager + from yandex_music import Pager, Track data['tracks'] = Track.de_list(data.get('tracks'), client) data['pager'] = Pager.de_json(data.get('pager'), client) diff --git a/yandex_music/artist/brief_info.py b/yandex_music/artist/brief_info.py index 94f0d9d9..a202f430 100644 --- a/yandex_music/artist/brief_info.py +++ b/yandex_music/artist/brief_info.py @@ -1,10 +1,10 @@ -from typing import Any, TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, Any, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Artist, Track, Album, Cover, PlaylistId, Video, Chart, Vinyl, Playlist + from yandex_music import Album, Artist, Chart, Client, Cover, Playlist, PlaylistId, Track, Video, Vinyl @model @@ -79,7 +79,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['BriefInfo']: return None data = super(BriefInfo, cls).de_json(data, client) - from yandex_music import Artist, Track, Album, Cover, PlaylistId, Video, Chart, Vinyl, Playlist + from yandex_music import Album, Artist, Chart, Cover, Playlist, PlaylistId, Track, Video, Vinyl data['playlists'] = Playlist.de_list(data.get('playlists'), client) data['artist'] = Artist.de_json(data.get('artist'), client) diff --git a/yandex_music/artist/link.py b/yandex_music/artist/link.py index 0f3e6ac9..ff9123ba 100644 --- a/yandex_music/artist/link.py +++ b/yandex_music/artist/link.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -63,7 +63,7 @@ def de_list(cls, data: list, client: 'Client') -> List['Link']: if not cls.is_valid_model_data(data, array=True): return [] - links = list() + links = [] for link in data: links.append(cls.de_json(link, client)) diff --git a/yandex_music/artist/vinyl.py b/yandex_music/artist/vinyl.py index 05a12aa8..8f70c5eb 100644 --- a/yandex_music/artist/vinyl.py +++ b/yandex_music/artist/vinyl.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -78,7 +78,7 @@ def de_list(cls, data: list, client: 'Client') -> List['Vinyl']: if not cls.is_valid_model_data(data, array=True): return [] - vinyls = list() + vinyls = [] for vinyl in data: vinyls.append(cls.de_json(vinyl, client)) diff --git a/yandex_music/base.py b/yandex_music/base.py index 459fe21b..c35d1ed4 100644 --- a/yandex_music/base.py +++ b/yandex_music/base.py @@ -1,8 +1,8 @@ import dataclasses -import logging import keyword +import logging from abc import ABCMeta -from typing import TYPE_CHECKING, Optional, Any +from typing import TYPE_CHECKING, Any, Optional if TYPE_CHECKING: from yandex_music import Client @@ -67,8 +67,8 @@ def de_json(cls, data: dict, client: Optional['Client']) -> Optional[dict]: fields = {f.name for f in dataclasses.fields(cls)} - cleaned_data = dict() - unknown_data = dict() + cleaned_data = {} + unknown_data = {} for k, v in data.items(): if k in fields: @@ -110,12 +110,11 @@ def to_dict(self, for_request=False) -> dict: def parse(val): if hasattr(val, 'to_dict'): return val.to_dict(for_request) - elif isinstance(val, list): + if isinstance(val, list): return [parse(it) for it in val] - elif isinstance(val, dict): + if isinstance(val, dict): return {key: parse(value) for key, value in val.items()} - else: - return val + return val data = self.__dict__.copy() data.pop('client', None) diff --git a/yandex_music/client.py b/yandex_music/client.py index a036e7bc..2bc63957 100644 --- a/yandex_music/client.py +++ b/yandex_music/client.py @@ -1,7 +1,7 @@ import functools import logging from datetime import datetime -from typing import Dict, List, Optional, Union, TypeVar, Callable, Any +from typing import Any, Callable, Dict, List, Optional, TypeVar, Union from yandex_music import ( Album, @@ -9,36 +9,36 @@ ArtistAlbums, ArtistTracks, BriefInfo, + ChartInfo, Dashboard, DownloadInfo, Experiments, Feed, Genre, Landing, + LandingList, Like, PermissionAlerts, Playlist, + PlaylistRecommendations, PromoCodeStatus, + Queue, + QueueItem, Search, Settings, ShotEvent, - Supplement, + SimilarTracks, StationResult, StationTracksResult, Status, Suggestions, - SimilarTracks, - TrackLyrics, + Supplement, + TagResult, Track, + TrackLyrics, TracksList, UserSettings, YandexMusicObject, - ChartInfo, - TagResult, - PlaylistRecommendations, - LandingList, - QueueItem, - Queue, __copyright__, __license__, __version__, @@ -855,13 +855,11 @@ def users_playlists( data = {'kinds': kind} result = self._request.post(url, data, *args, **kwargs) - return Playlist.de_list(result, self) - else: - url = f'{self.base_url}/users/{user_id}/playlists/{kind}' - result = self._request.get(url, *args, **kwargs) - return Playlist.de_json(result, self) + url = f'{self.base_url}/users/{user_id}/playlists/{kind}' + result = self._request.get(url, *args, **kwargs) + return Playlist.de_json(result, self) @log def users_playlists_recommendations(self, kind: Union[str, int], user_id: Union[str, int] = None, *args, **kwargs): @@ -2196,7 +2194,7 @@ def _dislike_action( action = 'remove' if remove else 'add-multiple' url = f'{self.base_url}/users/{user_id}/dislikes/tracks/{action}' - result = self._request.post(url, {f'track-ids': ids}, *args, **kwargs) + result = self._request.post(url, {'track-ids': ids}, *args, **kwargs) return 'revision' in result diff --git a/yandex_music/client_async.py b/yandex_music/client_async.py index 88b0b448..617bcdf8 100644 --- a/yandex_music/client_async.py +++ b/yandex_music/client_async.py @@ -5,7 +5,7 @@ import functools import logging from datetime import datetime -from typing import Dict, List, Optional, Union, TypeVar, Callable, Any +from typing import Any, Callable, Dict, List, Optional, TypeVar, Union from yandex_music import ( Album, @@ -13,36 +13,36 @@ ArtistAlbums, ArtistTracks, BriefInfo, + ChartInfo, Dashboard, DownloadInfo, Experiments, Feed, Genre, Landing, + LandingList, Like, PermissionAlerts, Playlist, + PlaylistRecommendations, PromoCodeStatus, + Queue, + QueueItem, Search, Settings, ShotEvent, - Supplement, + SimilarTracks, StationResult, StationTracksResult, Status, Suggestions, - SimilarTracks, - TrackLyrics, + Supplement, + TagResult, Track, + TrackLyrics, TracksList, UserSettings, YandexMusicObject, - ChartInfo, - TagResult, - PlaylistRecommendations, - LandingList, - QueueItem, - Queue, __copyright__, __license__, __version__, @@ -861,13 +861,11 @@ async def users_playlists( data = {'kinds': kind} result = await self._request.post(url, data, *args, **kwargs) - return Playlist.de_list(result, self) - else: - url = f'{self.base_url}/users/{user_id}/playlists/{kind}' - result = await self._request.get(url, *args, **kwargs) - return Playlist.de_json(result, self) + url = f'{self.base_url}/users/{user_id}/playlists/{kind}' + result = await self._request.get(url, *args, **kwargs) + return Playlist.de_json(result, self) @log async def users_playlists_recommendations( @@ -2214,7 +2212,7 @@ async def _dislike_action( action = 'remove' if remove else 'add-multiple' url = f'{self.base_url}/users/{user_id}/dislikes/tracks/{action}' - result = await self._request.post(url, {f'track-ids': ids}, *args, **kwargs) + result = await self._request.post(url, {'track-ids': ids}, *args, **kwargs) return 'revision' in result diff --git a/yandex_music/cover.py b/yandex_music/cover.py index 91204b3b..d81d7fbe 100644 --- a/yandex_music/cover.py +++ b/yandex_music/cover.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -132,7 +132,7 @@ def de_list(cls, data: list, client: 'Client') -> List['Cover']: if not cls.is_valid_model_data(data, array=True): return [] - covers = list() + covers = [] for cover in data: covers.append(cls.de_json(cover, client)) diff --git a/yandex_music/download_info.py b/yandex_music/download_info.py index 8217591c..877df245 100644 --- a/yandex_music/download_info.py +++ b/yandex_music/download_info.py @@ -1,15 +1,15 @@ -from typing import TYPE_CHECKING, Optional, List - -from hashlib import md5 import xml.dom.minidom as minidom +from hashlib import md5 +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client from xml.dom.minicompat import NodeList + from yandex_music import Client + SIGN_SALT = 'XGRlBW9FXlekgbPrRHuSiA' @@ -40,7 +40,7 @@ def __post_init__(self): self._id_attrs = (self.codec, self.bitrate_in_kbps, self.gain, self.preview, self.download_info_url) @staticmethod - def _get_text_node_data(elements: 'NodeList') -> str: + def _get_text_node_data(elements: 'NodeList') -> Optional[str]: """:obj:`str`: Получение текстовой информации из узлов XML элемента.""" for element in elements: nodes = element.childNodes @@ -48,13 +48,15 @@ def _get_text_node_data(elements: 'NodeList') -> str: if node.nodeType == node.TEXT_NODE: return node.data + return None + def __build_direct_link(self, xml: str) -> str: - doc = minidom.parseString(xml) + doc = minidom.parseString(xml) # noqa: S318 host = self._get_text_node_data(doc.getElementsByTagName('host')) path = self._get_text_node_data(doc.getElementsByTagName('path')) ts = self._get_text_node_data(doc.getElementsByTagName('ts')) s = self._get_text_node_data(doc.getElementsByTagName('s')) - sign = md5((SIGN_SALT + path[1::] + s).encode('utf-8')).hexdigest() + sign = md5((SIGN_SALT + path[1::] + s).encode('utf-8')).hexdigest() # noqa: S324 return f'https://{host}/get-mp3/{sign}/{ts}{path}' @@ -165,7 +167,7 @@ def de_list(cls, data: list, client: 'Client', get_direct_links: bool = False) - if not cls.is_valid_model_data(data, array=True): return [] - downloads_info = list() + downloads_info = [] for download_info in data: downloads_info.append(cls.de_json(download_info, client)) @@ -190,7 +192,7 @@ async def de_list_async(cls, data: dict, client: 'Client', get_direct_links: boo if not cls.is_valid_model_data(data, array=True): return [] - downloads_info = list() + downloads_info = [] for download_info in data: downloads_info.append(cls.de_json(download_info, client)) diff --git a/yandex_music/experiments.py b/yandex_music/experiments.py index 5ea3f987..674a4272 100644 --- a/yandex_music/experiments.py +++ b/yandex_music/experiments.py @@ -1,6 +1,5 @@ from typing import TYPE_CHECKING, Optional - from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/feed/album_event.py b/yandex_music/feed/album_event.py index e72a1011..7cc575ee 100644 --- a/yandex_music/feed/album_event.py +++ b/yandex_music/feed/album_event.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Album, Track + from yandex_music import Album, Client, Track @model @@ -60,7 +60,7 @@ def de_list(cls, data: list, client: 'Client') -> List['AlbumEvent']: if not cls.is_valid_model_data(data, array=True): return [] - album_events = list() + album_events = [] for album_event in data: album_events.append(cls.de_json(album_event, client)) diff --git a/yandex_music/feed/artist_event.py b/yandex_music/feed/artist_event.py index 3da1cf94..8ebb85b6 100644 --- a/yandex_music/feed/artist_event.py +++ b/yandex_music/feed/artist_event.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Artist, Track + from yandex_music import Artist, Client, Track @model @@ -65,7 +65,7 @@ def de_list(cls, data: list, client: 'Client') -> List['ArtistEvent']: if not cls.is_valid_model_data(data, array=True): return [] - artist_events = list() + artist_events = [] for artist_event in data: artist_events.append(cls.de_json(artist_event, client)) diff --git a/yandex_music/feed/day.py b/yandex_music/feed/day.py index 52a6f7f2..7883ae4e 100644 --- a/yandex_music/feed/day.py +++ b/yandex_music/feed/day.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -65,7 +65,7 @@ def de_list(cls, data: list, client: 'Client') -> List['Day']: if not cls.is_valid_model_data(data, array=True): return [] - days = list() + days = [] for day in data: days.append(cls.de_json(day, client)) diff --git a/yandex_music/feed/event.py b/yandex_music/feed/event.py index f5954196..3b11d00d 100644 --- a/yandex_music/feed/event.py +++ b/yandex_music/feed/event.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Track, AlbumEvent, ArtistEvent + from yandex_music import AlbumEvent, ArtistEvent, Client, Track @model @@ -67,7 +67,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Event']: return None data = super(Event, cls).de_json(data, client) - from yandex_music import Track, AlbumEvent, ArtistEvent + from yandex_music import AlbumEvent, ArtistEvent, Track data['tracks'] = Track.de_list(data.get('tracks'), client) data['albums'] = AlbumEvent.de_list(data.get('albums'), client) @@ -89,7 +89,7 @@ def de_list(cls, data: list, client: 'Client') -> List['Event']: if not cls.is_valid_model_data(data, array=True): return [] - events = list() + events = [] for event in data: events.append(cls.de_json(event, client)) diff --git a/yandex_music/feed/feed.py b/yandex_music/feed/feed.py index bf2cb26b..f36f150e 100644 --- a/yandex_music/feed/feed.py +++ b/yandex_music/feed/feed.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, GeneratedPlaylist, Day + from yandex_music import Client, Day, GeneratedPlaylist @model @@ -54,7 +54,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Feed']: return None data = super(Feed, cls).de_json(data, client) - from yandex_music import GeneratedPlaylist, Day + from yandex_music import Day, GeneratedPlaylist data['generated_playlists'] = GeneratedPlaylist.de_list(data.get('generated_playlists'), client) data['days'] = Day.de_list(data.get('days'), client) diff --git a/yandex_music/feed/generated_playlist.py b/yandex_music/feed/generated_playlist.py index 76bf915d..ce3bbacd 100644 --- a/yandex_music/feed/generated_playlist.py +++ b/yandex_music/feed/generated_playlist.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/feed/track_with_ads.py b/yandex_music/feed/track_with_ads.py index 4825e955..16d08b46 100644 --- a/yandex_music/feed/track_with_ads.py +++ b/yandex_music/feed/track_with_ads.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -62,7 +62,7 @@ def de_list(cls, data: list, client: 'Client') -> List['TrackWithAds']: if not cls.is_valid_model_data(data, array=True): return [] - tracks_with_ads = list() + tracks_with_ads = [] for track_with_ads in data: tracks_with_ads.append(cls.de_json(track_with_ads, client)) diff --git a/yandex_music/genre/genre.py b/yandex_music/genre/genre.py index e0a75086..681cce57 100644 --- a/yandex_music/genre/genre.py +++ b/yandex_music/genre/genre.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List, Dict +from typing import TYPE_CHECKING, Dict, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Title, Icon, Images + from yandex_music import Client, Icon, Images, Title @model @@ -63,7 +63,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Genre']: return None data = super(Genre, cls).de_json(data, client) - from yandex_music import Title, Icon, Images + from yandex_music import Icon, Images, Title data['titles'] = Title.de_dict(data.get('titles'), client) data['images'] = Images.de_json(data.get('images'), client) diff --git a/yandex_music/genre/title.py b/yandex_music/genre/title.py index adc56a2c..c4007fc7 100644 --- a/yandex_music/genre/title.py +++ b/yandex_music/genre/title.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, Dict +from typing import TYPE_CHECKING, Dict, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -56,7 +56,7 @@ def de_dict(cls, data, client) -> Dict[str, Optional['Title']]: if not data: return {} - titles = dict() + titles = {} for lang, title in data.items(): titles.update({lang: cls.de_json(title, client)}) diff --git a/yandex_music/landing/block.py b/yandex_music/landing/block.py index 090f9f2e..6379e518 100644 --- a/yandex_music/landing/block.py +++ b/yandex_music/landing/block.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List, Union +from typing import TYPE_CHECKING, List, Optional, Union from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, BlockEntity, PersonalPlaylistsData, PlayContextsData + from yandex_music import BlockEntity, Client, PersonalPlaylistsData, PlayContextsData @model @@ -56,7 +56,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Block']: return None data = super(Block, cls).de_json(data, client) - from yandex_music import BlockEntity, PlayContextsData, PersonalPlaylistsData + from yandex_music import BlockEntity, PersonalPlaylistsData, PlayContextsData data['entities'] = BlockEntity.de_list(data.get('entities'), client) @@ -82,7 +82,7 @@ def de_list(cls, data: list, client: 'Client') -> List['Block']: if not cls.is_valid_model_data(data, array=True): return [] - blocks = list() + blocks = [] for block in data: blocks.append(cls.de_json(block, client)) diff --git a/yandex_music/landing/block_entity.py b/yandex_music/landing/block_entity.py index c26b733e..473f42f0 100644 --- a/yandex_music/landing/block_entity.py +++ b/yandex_music/landing/block_entity.py @@ -1,14 +1,14 @@ -from typing import TYPE_CHECKING, Optional, List, Union +from typing import TYPE_CHECKING, List, Optional, Union from yandex_music import ( - YandexMusicObject, - Promotion, Album, - Playlist, - MixLink, - PlayContext, ChartItem, GeneratedPlaylist, + MixLink, + PlayContext, + Playlist, + Promotion, + YandexMusicObject, ) from yandex_music.utils import model @@ -86,7 +86,7 @@ def de_list(cls, data: list, client: 'Client') -> List['BlockEntity']: if not cls.is_valid_model_data(data, array=True): return [] - entities = list() + entities = [] for entity in data: entities.append(cls.de_json(entity, client)) diff --git a/yandex_music/landing/chart.py b/yandex_music/landing/chart.py index 6d671da1..3466f121 100644 --- a/yandex_music/landing/chart.py +++ b/yandex_music/landing/chart.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/landing/chart_info.py b/yandex_music/landing/chart_info.py index e0f47e0b..66875277 100644 --- a/yandex_music/landing/chart_info.py +++ b/yandex_music/landing/chart_info.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Optional -from yandex_music import YandexMusicObject, Playlist, ChartInfoMenu +from yandex_music import ChartInfoMenu, Playlist, YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: diff --git a/yandex_music/landing/chart_info_menu.py b/yandex_music/landing/chart_info_menu.py index fafaf3ce..d3a25cea 100644 --- a/yandex_music/landing/chart_info_menu.py +++ b/yandex_music/landing/chart_info_menu.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, List, Optional -from yandex_music import YandexMusicObject, ChartInfoMenuItem +from yandex_music import ChartInfoMenuItem, YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: diff --git a/yandex_music/landing/chart_info_menu_item.py b/yandex_music/landing/chart_info_menu_item.py index b75768f0..bad5f10b 100644 --- a/yandex_music/landing/chart_info_menu_item.py +++ b/yandex_music/landing/chart_info_menu_item.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/landing/chart_item.py b/yandex_music/landing/chart_item.py index 33945b17..0e0d0000 100644 --- a/yandex_music/landing/chart_item.py +++ b/yandex_music/landing/chart_item.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Track, Chart + from yandex_music import Chart, Client, Track @model @@ -60,7 +60,7 @@ def de_list(cls, data: list, client: 'Client') -> List['ChartItem']: if not cls.is_valid_model_data(data, array=True): return [] - tracks = list() + tracks = [] for track in data: tracks.append(cls.de_json(track, client)) diff --git a/yandex_music/landing/landing.py b/yandex_music/landing/landing.py index 3a6f8445..24406b66 100644 --- a/yandex_music/landing/landing.py +++ b/yandex_music/landing/landing.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List, Union +from typing import TYPE_CHECKING, List, Optional, Union from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Block + from yandex_music import Block, Client @model diff --git a/yandex_music/landing/landing_list.py b/yandex_music/landing/landing_list.py index 68d87be0..8a25c8c8 100644 --- a/yandex_music/landing/landing_list.py +++ b/yandex_music/landing/landing_list.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -40,7 +40,7 @@ def __post_init__(self): self._id_attrs = (self.id, self.new_releases, self.new_playlists, self.podcasts) @classmethod - def de_json(cls, data: dict, client: 'Client') -> Optional['Chart']: + def de_json(cls, data: dict, client: 'Client') -> Optional['LandingList']: """Десериализация объекта. Args: diff --git a/yandex_music/landing/mix_link.py b/yandex_music/landing/mix_link.py index 488ebd14..00029cb8 100644 --- a/yandex_music/landing/mix_link.py +++ b/yandex_music/landing/mix_link.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.exceptions import YandexMusicError @@ -71,7 +71,7 @@ def get_cover_white_url(self, size: str = '200x200') -> str: """ if not self.cover_white: - raise YandexMusicError('You can\'t get cover white because it\'s None.') + raise YandexMusicError("You can't get cover white because it's None.") return f'https://{self.cover_white.replace("%%", size)}' @@ -238,7 +238,7 @@ def de_list(cls, data: list, client: 'Client') -> List['MixLink']: if not cls.is_valid_model_data(data, array=True): return [] - mix_links = list() + mix_links = [] for mix_link in data: mix_links.append(cls.de_json(mix_link, client)) diff --git a/yandex_music/landing/play_context.py b/yandex_music/landing/play_context.py index 97a72676..ee93b919 100644 --- a/yandex_music/landing/play_context.py +++ b/yandex_music/landing/play_context.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/landing/play_contexts_data.py b/yandex_music/landing/play_contexts_data.py index 8cb9b7d1..34dd8103 100644 --- a/yandex_music/landing/play_contexts_data.py +++ b/yandex_music/landing/play_contexts_data.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/landing/promotion.py b/yandex_music/landing/promotion.py index fb5e09d4..a03bfc02 100644 --- a/yandex_music/landing/promotion.py +++ b/yandex_music/landing/promotion.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -136,7 +136,7 @@ def de_list(cls, data: list, client: 'Client') -> List['Promotion']: if not cls.is_valid_model_data(data, array=True): return [] - promotions = list() + promotions = [] for promotion in data: promotions.append(cls.de_json(promotion, client)) diff --git a/yandex_music/landing/track_id.py b/yandex_music/landing/track_id.py index f37a4d1d..ebe159d1 100644 --- a/yandex_music/landing/track_id.py +++ b/yandex_music/landing/track_id.py @@ -1,9 +1,8 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model - if TYPE_CHECKING: from yandex_music import Client, Track diff --git a/yandex_music/landing/track_short_old.py b/yandex_music/landing/track_short_old.py index 01460d08..35bf2a7f 100644 --- a/yandex_music/landing/track_short_old.py +++ b/yandex_music/landing/track_short_old.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -64,7 +64,7 @@ def de_list(cls, data: list, client: 'Client') -> List['TrackShortOld']: if not cls.is_valid_model_data(data, array=True): return [] - tracks = list() + tracks = [] for track in data: tracks.append(cls.de_json(track, client)) diff --git a/yandex_music/like.py b/yandex_music/like.py index 1e70abb6..138e49eb 100644 --- a/yandex_music/like.py +++ b/yandex_music/like.py @@ -1,4 +1,4 @@ -from typing import List, Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, List, Optional from yandex_music import Album, Artist, Playlist, YandexMusicObject from yandex_music.utils import model @@ -95,7 +95,7 @@ def de_list(cls, data: list, client: 'Client', type_: str = None) -> List['Like' if not cls.is_valid_model_data(data, array=True): return [] - likes = list() + likes = [] for like in data: likes.append(cls.de_json(like, client, type_)) diff --git a/yandex_music/permission_alerts.py b/yandex_music/permission_alerts.py index 46ffa4b9..b63a1e7a 100644 --- a/yandex_music/permission_alerts.py +++ b/yandex_music/permission_alerts.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/playlist/brand.py b/yandex_music/playlist/brand.py index 022453e6..96a41d84 100644 --- a/yandex_music/playlist/brand.py +++ b/yandex_music/playlist/brand.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/playlist/custom_wave.py b/yandex_music/playlist/custom_wave.py index 3c745bf4..c1c2f1b2 100644 --- a/yandex_music/playlist/custom_wave.py +++ b/yandex_music/playlist/custom_wave.py @@ -1,4 +1,4 @@ -from typing import Any, TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/playlist/made_for.py b/yandex_music/playlist/made_for.py index d639d3d6..ddaac3a0 100644 --- a/yandex_music/playlist/made_for.py +++ b/yandex_music/playlist/made_for.py @@ -4,7 +4,7 @@ from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, User, CaseForms + from yandex_music import CaseForms, Client, User @model @@ -39,7 +39,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['MadeFor']: return None data = super(MadeFor, cls).de_json(data, client) - from yandex_music import User, CaseForms + from yandex_music import CaseForms, User data['user_info'] = User.de_json(data.get('user_info'), client) data['case_forms'] = CaseForms.de_json(data.get('case_forms'), client) diff --git a/yandex_music/playlist/playlist.py b/yandex_music/playlist/playlist.py index 5b7bdf2c..366b7af1 100644 --- a/yandex_music/playlist/playlist.py +++ b/yandex_music/playlist/playlist.py @@ -1,25 +1,25 @@ -from typing import Any, TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, Any, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: from yandex_music import ( + Artist, + Brand, Client, - User, + Contest, Cover, + CustomWave, MadeFor, - TrackShort, - PlaylistAbsence, + OpenGraphData, + Pager, PlayCounter, + PlaylistAbsence, PlaylistRecommendations, - Artist, TrackId, - Contest, - OpenGraphData, - Brand, - Pager, - CustomWave, + TrackShort, + User, ) @@ -353,24 +353,24 @@ async def fetch_tracks_async(self, *args, **kwargs) -> List['TrackShort']: """ return (await self.client.users_playlists(self.kind, self.owner.uid, *args, **kwargs)).tracks - def insert_track(self, track_id: int, album_id: int, *args, **kwargs) -> Optional['Playlist']: + def insert_track(self, track_id: int, album_id: int, **kwargs) -> Optional['Playlist']: """Сокращение для:: client.users_playlists_insert_track(self.kind, track_id, album_id, user_id=self.owner.uid, revision=self.revision, *args, **kwargs) """ return self.client.users_playlists_insert_track( - self.kind, track_id, album_id, user_id=self.owner.uid, revision=self.revision, *args, **kwargs + self.kind, track_id, album_id, user_id=self.owner.uid, revision=self.revision, **kwargs ) - async def insert_track_async(self, track_id: int, album_id: int, *args, **kwargs) -> Optional['Playlist']: + async def insert_track_async(self, track_id: int, album_id: int, **kwargs) -> Optional['Playlist']: """Сокращение для:: await client.users_playlists_insert_track(self.kind, track_id, album_id, user_id=self.owner.uid, revision=self.revision, *args, **kwargs) """ return await self.client.users_playlists_insert_track( - self.kind, track_id, album_id, user_id=self.owner.uid, revision=self.revision, *args, **kwargs + self.kind, track_id, album_id, user_id=self.owner.uid, revision=self.revision, **kwargs ) def delete_tracks(self, from_: int, to: int, *args, **kwargs) -> Optional['Playlist']: @@ -421,19 +421,19 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Playlist']: data = super(Playlist, cls).de_json(data, client) from yandex_music import ( - User, - MadeFor, - Cover, - PlayCounter, - TrackShort, - PlaylistAbsence, Artist, - TrackId, - Contest, - OpenGraphData, Brand, + Contest, + Cover, CustomWave, + MadeFor, + OpenGraphData, Pager, + PlayCounter, + PlaylistAbsence, + TrackId, + TrackShort, + User, ) data['owner'] = User.de_json(data.get('owner'), client) diff --git a/yandex_music/playlist/playlist_id.py b/yandex_music/playlist/playlist_id.py index fcb6070e..d2be734f 100644 --- a/yandex_music/playlist/playlist_id.py +++ b/yandex_music/playlist/playlist_id.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -74,7 +74,7 @@ def de_list(cls, data: list, client: 'Client') -> List['PlaylistId']: if not cls.is_valid_model_data(data, array=True): return [] - playlist_ids = list() + playlist_ids = [] for playlist_id in data: playlist_ids.append(cls.de_json(playlist_id, client)) diff --git a/yandex_music/playlist/playlist_recommendation.py b/yandex_music/playlist/playlist_recommendation.py index 67cd02ca..e4e90649 100644 --- a/yandex_music/playlist/playlist_recommendation.py +++ b/yandex_music/playlist/playlist_recommendation.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/playlist/tag_result.py b/yandex_music/playlist/tag_result.py index 213abc1d..1845d424 100644 --- a/yandex_music/playlist/tag_result.py +++ b/yandex_music/playlist/tag_result.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -39,7 +39,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['TagResult']: return None data = super(TagResult, cls).de_json(data, client) - from yandex_music import Tag, PlaylistId + from yandex_music import PlaylistId, Tag data['tag'] = Tag.de_json(data.get('tag'), client) data['ids'] = PlaylistId.de_list(data.get('ids'), client) diff --git a/yandex_music/playlist/user.py b/yandex_music/playlist/user.py index b0a55ad9..e85f1f5f 100644 --- a/yandex_music/playlist/user.py +++ b/yandex_music/playlist/user.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/queue/queue.py b/yandex_music/queue/queue.py index 15405ff7..38b8b3e7 100644 --- a/yandex_music/queue/queue.py +++ b/yandex_music/queue/queue.py @@ -1,10 +1,10 @@ -from typing import List, TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, TrackId, Context + from yandex_music import Client, Context, TrackId @model @@ -50,7 +50,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Queue']: if not cls.is_valid_model_data(data): return None - from yandex_music import TrackId, Context + from yandex_music import Context, TrackId data = super(Queue, cls).de_json(data, client) data['tracks'] = TrackId.de_list(data.get('tracks'), client) diff --git a/yandex_music/queue/queue_item.py b/yandex_music/queue/queue_item.py index 6fd8b5f3..46ff565b 100644 --- a/yandex_music/queue/queue_item.py +++ b/yandex_music/queue/queue_item.py @@ -1,4 +1,4 @@ -from typing import List, TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/rotor/dashboard.py b/yandex_music/rotor/dashboard.py index 5316b68b..cb949c68 100644 --- a/yandex_music/rotor/dashboard.py +++ b/yandex_music/rotor/dashboard.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/rotor/enum.py b/yandex_music/rotor/enum.py index a87889a1..1be77a1d 100644 --- a/yandex_music/rotor/enum.py +++ b/yandex_music/rotor/enum.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/rotor/restrictions.py b/yandex_music/rotor/restrictions.py index 1ea3c4e6..ddc41536 100644 --- a/yandex_music/rotor/restrictions.py +++ b/yandex_music/rotor/restrictions.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Optional -from yandex_music import YandexMusicObject, Enum, DiscreteScale +from yandex_music import DiscreteScale, Enum, YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: diff --git a/yandex_music/rotor/sequence.py b/yandex_music/rotor/sequence.py index e9f590b5..af6102af 100644 --- a/yandex_music/rotor/sequence.py +++ b/yandex_music/rotor/sequence.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -64,7 +64,7 @@ def de_list(cls, data: list, client: 'Client') -> List['Sequence']: if not cls.is_valid_model_data(data, array=True): return [] - sequences = list() + sequences = [] for sequence in data: sequences.append(cls.de_json(sequence, client)) diff --git a/yandex_music/rotor/station.py b/yandex_music/rotor/station.py index f5e4fc29..6b9d20e8 100644 --- a/yandex_music/rotor/station.py +++ b/yandex_music/rotor/station.py @@ -4,7 +4,7 @@ from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Id, Icon, Restrictions + from yandex_music import Client, Icon, Id, Restrictions @model @@ -70,7 +70,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Station']: return None data = super(Station, cls).de_json(data, client) - from yandex_music import Id, Icon, Restrictions + from yandex_music import Icon, Id, Restrictions data['id'] = Id.de_json(data.get('id'), client) data['parent_id'] = Id.de_json(data.get('parent_id'), client) diff --git a/yandex_music/rotor/station_result.py b/yandex_music/rotor/station_result.py index ef752810..bb610d87 100644 --- a/yandex_music/rotor/station_result.py +++ b/yandex_music/rotor/station_result.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Station, RotorSettings, AdParams + from yandex_music import AdParams, Client, RotorSettings, Station @model @@ -12,7 +12,8 @@ class StationResult(YandexMusicObject): """Класс, представляющий радиостанцию с настройками. Note: - Известные значения `custom_name`: `Танцую`, `R'n'B`, `Отдыхаю`, `Просыпаюсь`, `Тренируюсь`, `В дороге`, `Работаю`, `Засыпаю`. + Известные значения `custom_name`: `Танцую`, `R'n'B`, `Отдыхаю`, `Просыпаюсь`, + `Тренируюсь`, `В дороге`, `Работаю`, `Засыпаю`. Attributes: station (:obj:`yandex_music.Station` | :obj:`None`): Станция. @@ -56,7 +57,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['StationResult']: return None data = super(StationResult, cls).de_json(data, client) - from yandex_music import Station, RotorSettings, AdParams + from yandex_music import AdParams, RotorSettings, Station data['station'] = Station.de_json(data.get('station'), client) data['settings'] = RotorSettings.de_json(data.get('settings'), client) @@ -79,7 +80,7 @@ def de_list(cls, data: list, client: 'Client') -> List['StationResult']: if not cls.is_valid_model_data(data, array=True): return [] - station_results = list() + station_results = [] for station_result in data: station_results.append(cls.de_json(station_result, client)) diff --git a/yandex_music/rotor/station_tracks_result.py b/yandex_music/rotor/station_tracks_result.py index 5c91c096..f0ac4afd 100644 --- a/yandex_music/rotor/station_tracks_result.py +++ b/yandex_music/rotor/station_tracks_result.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/rotor/value.py b/yandex_music/rotor/value.py index 367d00fe..1548dfc0 100644 --- a/yandex_music/rotor/value.py +++ b/yandex_music/rotor/value.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -56,7 +56,7 @@ def de_list(cls, data: list, client: 'Client') -> List['Value']: if not cls.is_valid_model_data(data, array=True): return [] - values = list() + values = [] for value in data: values.append(cls.de_json(value, client)) diff --git a/yandex_music/search/best.py b/yandex_music/search/best.py index a9e2a9a1..33717537 100644 --- a/yandex_music/search/best.py +++ b/yandex_music/search/best.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Optional, Union -from yandex_music import YandexMusicObject, Artist, Album, Track, Playlist, Video, User +from yandex_music import Album, Artist, Playlist, Track, User, Video, YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: diff --git a/yandex_music/search/search.py b/yandex_music/search/search.py index b5fad21a..af946a5b 100644 --- a/yandex_music/search/search.py +++ b/yandex_music/search/search.py @@ -1,10 +1,10 @@ from typing import TYPE_CHECKING, Optional -from yandex_music import YandexMusicObject, Album, Artist, Playlist, Track, Video, User +from yandex_music import Album, Artist, Playlist, Track, User, Video, YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Best, SearchResult + from yandex_music import Best, Client, SearchResult @model @@ -137,7 +137,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Search']: return None data = super(Search, cls).de_json(data, client) - from yandex_music import SearchResult, Best + from yandex_music import Best, SearchResult # в ОЧЕНЬ редких случаях сервер творит дичь и может вернуть результат плейлистов в поле artists # или вернуть в поле users результаты с плейлистами diff --git a/yandex_music/search/search_result.py b/yandex_music/search/search_result.py index 76a55553..99b01c1c 100644 --- a/yandex_music/search/search_result.py +++ b/yandex_music/search/search_result.py @@ -1,6 +1,6 @@ -from typing import TYPE_CHECKING, Optional, List, Union, TypeVar, Generic, Type, Dict +from typing import TYPE_CHECKING, Dict, Generic, List, Optional, Type, TypeVar, Union -from yandex_music import YandexMusicObject, Artist, Album, Track, Playlist, Video, User +from yandex_music import Album, Artist, Playlist, Track, User, Video, YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: diff --git a/yandex_music/search/suggestions.py b/yandex_music/search/suggestions.py index add90d23..2d70afd7 100644 --- a/yandex_music/search/suggestions.py +++ b/yandex_music/search/suggestions.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Best + from yandex_music import Best, Client @model diff --git a/yandex_music/settings.py b/yandex_music/settings.py index 533557ee..ea8fa603 100644 --- a/yandex_music/settings.py +++ b/yandex_music/settings.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Product, Price + from yandex_music import Client, Price, Product @model @@ -45,7 +45,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Settings']: return None data = super(Settings, cls).de_json(data, client) - from yandex_music import Product, Price + from yandex_music import Price, Product data['in_app_products'] = Product.de_list(data.get('in_app_products'), client) data['native_products'] = Product.de_list(data.get('native_products'), client) diff --git a/yandex_music/shot/shot.py b/yandex_music/shot/shot.py index e6e540e5..73ddc8ec 100644 --- a/yandex_music/shot/shot.py +++ b/yandex_music/shot/shot.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -68,7 +68,7 @@ def de_list(cls, data: list, client: 'Client') -> List['Shot']: if not cls.is_valid_model_data(data, array=True): return [] - shots = list() + shots = [] for shot in data: shots.append(cls.de_json(shot, client)) diff --git a/yandex_music/shot/shot_event.py b/yandex_music/shot/shot_event.py index 7b3a1e50..c66a5206 100644 --- a/yandex_music/shot/shot_event.py +++ b/yandex_music/shot/shot_event.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/supplement/supplement.py b/yandex_music/supplement/supplement.py index e84b1630..c89b3747 100644 --- a/yandex_music/supplement/supplement.py +++ b/yandex_music/supplement/supplement.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/supplement/video_supplement.py b/yandex_music/supplement/video_supplement.py index c73c880a..dbafb937 100644 --- a/yandex_music/supplement/video_supplement.py +++ b/yandex_music/supplement/video_supplement.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -66,7 +66,7 @@ def de_list(cls, data: list, client: 'Client') -> List['VideoSupplement']: if not cls.is_valid_model_data(data, array=True): return [] - videos = list() + videos = [] for video in data: videos.append(cls.de_json(video, client)) diff --git a/yandex_music/track/licence_text_part.py b/yandex_music/track/licence_text_part.py index 97b06644..f5b75fac 100644 --- a/yandex_music/track/licence_text_part.py +++ b/yandex_music/track/licence_text_part.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -25,7 +25,7 @@ def __post_init__(self): self._id_attrs = (self.text,) @classmethod - def de_json(cls, data: dict, client: 'Client') -> Optional['PassportPhone']: + def de_json(cls, data: dict, client: 'Client') -> Optional['LicenceTextPart']: """Десериализация объекта. Args: diff --git a/yandex_music/track/lyrics_major.py b/yandex_music/track/lyrics_major.py index bcad7307..9859d513 100644 --- a/yandex_music/track/lyrics_major.py +++ b/yandex_music/track/lyrics_major.py @@ -3,7 +3,6 @@ from yandex_music import YandexMusicObject from yandex_music.utils import model - if TYPE_CHECKING: from yandex_music import Client diff --git a/yandex_music/track/poetry_lover_match.py b/yandex_music/track/poetry_lover_match.py index 8d36ec8b..d682f617 100644 --- a/yandex_music/track/poetry_lover_match.py +++ b/yandex_music/track/poetry_lover_match.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List +from typing import TYPE_CHECKING, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/track/track.py b/yandex_music/track/track.py index 36b39f9a..0d749dc1 100644 --- a/yandex_music/track/track.py +++ b/yandex_music/track/track.py @@ -1,24 +1,24 @@ -from typing import TYPE_CHECKING, Optional, List, Union +from typing import TYPE_CHECKING, List, Optional, Union from yandex_music import YandexMusicObject -from yandex_music.utils import model from yandex_music.exceptions import InvalidBitrateError +from yandex_music.utils import model if TYPE_CHECKING: from yandex_music import ( - Client, - Normalization, - Major, + R128, Album, Artist, - Supplement, + Client, DownloadInfo, - User, + LyricsInfo, + Major, MetaData, + Normalization, PoetryLoverMatch, + Supplement, TrackLyrics, - LyricsInfo, - R128, + User, ) @@ -399,8 +399,8 @@ def download_bytes(self, codec: str = 'mp3', bitrate_in_kbps: int = 192) -> byte info = self.get_specific_download_info(codec, bitrate_in_kbps) if info: return info.download_bytes() - else: - raise InvalidBitrateError('Unavailable bitrate') + + raise InvalidBitrateError('Unavailable bitrate') async def download_bytes_async(self, codec: str = 'mp3', bitrate_in_kbps: int = 192) -> bytes: """Загрузка трека и возврат в виде байтов. @@ -423,8 +423,8 @@ async def download_bytes_async(self, codec: str = 'mp3', bitrate_in_kbps: int = info = await self.get_specific_download_info_async(codec, bitrate_in_kbps) if info: return await info.download_bytes_async() - else: - raise InvalidBitrateError('Unavailable bitrate') + + raise InvalidBitrateError('Unavailable bitrate') def like(self, *args, **kwargs) -> bool: """Сокращение для:: @@ -485,7 +485,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Track']: return None data = super(Track, cls).de_json(data, client) - from yandex_music import Normalization, Major, Album, Artist, User, MetaData, PoetryLoverMatch, R128, LyricsInfo + from yandex_music import R128, Album, Artist, LyricsInfo, Major, MetaData, Normalization, PoetryLoverMatch, User data['albums'] = Album.de_list(data.get('albums'), client) data['artists'] = Artist.de_list(data.get('artists'), client) diff --git a/yandex_music/track/track_lyrics.py b/yandex_music/track/track_lyrics.py index df0d6109..ec245828 100644 --- a/yandex_music/track/track_lyrics.py +++ b/yandex_music/track/track_lyrics.py @@ -3,7 +3,6 @@ from yandex_music import YandexMusicObject from yandex_music.utils import model - if TYPE_CHECKING: from yandex_music import Client, LyricsMajor diff --git a/yandex_music/track/tracks_similar.py b/yandex_music/track/tracks_similar.py index 1d946145..4d063434 100644 --- a/yandex_music/track/tracks_similar.py +++ b/yandex_music/track/tracks_similar.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List, Iterator +from typing import TYPE_CHECKING, Iterator, List, Optional from yandex_music import YandexMusicObject from yandex_music.utils import model diff --git a/yandex_music/track_short.py b/yandex_music/track_short.py index 0736223f..91936ccb 100644 --- a/yandex_music/track_short.py +++ b/yandex_music/track_short.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List, Union +from typing import TYPE_CHECKING, List, Optional, Union -from yandex_music.utils import model from yandex_music import YandexMusicObject +from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, Track, Chart + from yandex_music import Chart, Client, Track @model @@ -78,7 +78,7 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['TrackShort']: return None data = super(TrackShort, cls).de_json(data, client) - from yandex_music import Track, Chart + from yandex_music import Chart, Track data['track'] = Track.de_json(data.get('track'), client) data['chart'] = Chart.de_json(data.get('chart'), client) diff --git a/yandex_music/tracks_list.py b/yandex_music/tracks_list.py index 3e8628ce..b096697a 100644 --- a/yandex_music/tracks_list.py +++ b/yandex_music/tracks_list.py @@ -1,10 +1,10 @@ -from typing import TYPE_CHECKING, Optional, List, Iterator +from typing import TYPE_CHECKING, Iterator, List, Optional -from yandex_music.utils import model from yandex_music import YandexMusicObject +from yandex_music.utils import model if TYPE_CHECKING: - from yandex_music import Client, TrackShort, Track + from yandex_music import Client, Track, TrackShort @model diff --git a/yandex_music/utils/request.py b/yandex_music/utils/request.py index 331038ed..5faee703 100644 --- a/yandex_music/utils/request.py +++ b/yandex_music/utils/request.py @@ -1,25 +1,23 @@ -import re -import logging -import keyword - -from typing import TYPE_CHECKING, Optional, Union - # Не используется ujson из-за отсутствия в нём object_hook'a # Отправка вообще application/x-www-form-urlencoded, а не JSON'a # https://github.com/psf/requests/blob/master/requests/models.py#L508 import json +import keyword +import logging +import re +from typing import TYPE_CHECKING, Optional, Union import requests -from yandex_music.utils.response import Response from yandex_music.exceptions import ( - UnauthorizedError, BadRequestError, NetworkError, - YandexMusicError, - TimedOutError, NotFoundError, + TimedOutError, + UnauthorizedError, + YandexMusicError, ) +from yandex_music.utils.response import Response if TYPE_CHECKING: from yandex_music import Client @@ -172,18 +170,18 @@ def _parse(self, json_data: bytes) -> Optional[Response]: decoded_s = json_data.decode('utf-8') data = json.loads(decoded_s, object_hook=Request._object_hook) - except UnicodeDecodeError: + except UnicodeDecodeError as e: logging.getLogger(__name__).debug('Logging raw invalid UTF-8 response:\n%r', json_data) - raise YandexMusicError('Server response could not be decoded using UTF-8') - except (AttributeError, ValueError): - raise YandexMusicError('Invalid server response') + raise YandexMusicError('Server response could not be decoded using UTF-8') from e + except (AttributeError, ValueError) as e: + raise YandexMusicError('Invalid server response') from e if data.get('result') is None: data = {'result': data, 'error': data.get('error'), 'error_description': data.get('error_description')} return Response.de_json(data, self.client) - def _request_wrapper(self, *args, **kwargs): + def _request_wrapper(self, *args, **kwargs): # noqa: C901 """Обёртка над запросом библиотеки `requests`. Note: @@ -199,7 +197,8 @@ def _request_wrapper(self, *args, **kwargs): Raises: :class:`yandex_music.exceptions.TimedOutError`: При превышении времени ожидания. - :class:`yandex_music.exceptions.UnauthorizedError`: При невалидном токене, долгом ожидании прямой ссылки на файл. + :class:`yandex_music.exceptions.UnauthorizedError`: При невалидном токене, + долгом ожидании прямой ссылки на файл. :class:`yandex_music.exceptions.BadRequestError`: При неправильном запросе. :class:`yandex_music.exceptions.NetworkError`: При проблемах с сетью. """ @@ -213,10 +212,10 @@ def _request_wrapper(self, *args, **kwargs): try: resp = requests.request(*args, **kwargs) - except requests.Timeout: - raise TimedOutError() + except requests.Timeout as e: + raise TimedOutError from e except requests.RequestException as e: - raise NetworkError(e) + raise NetworkError(e) from e if 200 <= resp.status_code <= 299: return resp.content @@ -229,20 +228,20 @@ def _request_wrapper(self, *args, **kwargs): if resp.status_code in (401, 403): raise UnauthorizedError(message) - elif resp.status_code == 400: + if resp.status_code == 400: raise BadRequestError(message) - elif resp.status_code == 404: + if resp.status_code == 404: raise NotFoundError(message) - elif resp.status_code in (409, 413): + if resp.status_code in (409, 413): raise NetworkError(message) - elif resp.status_code == 502: + if resp.status_code == 502: raise NetworkError('Bad Gateway') - else: - raise NetworkError(f'{message} ({resp.status_code}): {resp.content}') + + raise NetworkError(f'{message} ({resp.status_code}): {resp.content}') def get( - self, url: str, params: dict = None, timeout: Union[int, float] = default_timeout, *args, **kwargs + self, url: str, params: dict = None, timeout: Union[int, float] = default_timeout, **kwargs ) -> Union[dict, str]: """Отправка GET запроса. @@ -251,7 +250,6 @@ def get( params (:obj:`str`): GET параметры для запроса. timeout (:obj:`int` | :obj:`float`): Используется как время ожидания ответа от сервера вместо указанного при создании пула. - *args: Произвольные аргументы для `requests.request`. **kwargs: Произвольные ключевые аргументы для `requests.request`. Returns: @@ -261,12 +259,12 @@ def get( :class:`yandex_music.exceptions.YandexMusicError`: Базовое исключение библиотеки. """ result = self._request_wrapper( - 'GET', url, params=params, headers=self.headers, proxies=self.proxies, timeout=timeout, *args, **kwargs + 'GET', url, params=params, headers=self.headers, proxies=self.proxies, timeout=timeout, **kwargs ) return self._parse(result).get_result() - def post(self, url, data=None, timeout=default_timeout, *args, **kwargs) -> Union[dict, str]: + def post(self, url, data=None, timeout=default_timeout, **kwargs) -> Union[dict, str]: """Отправка POST запроса. Args: @@ -274,7 +272,6 @@ def post(self, url, data=None, timeout=default_timeout, *args, **kwargs) -> Unio data (:obj:`str`): POST тело запроса. timeout (:obj:`int` | :obj:`float`): Используется как время ожидания ответа от сервера вместо указанного при создании пула. - *args: Произвольные аргументы для `requests.request`. **kwargs: Произвольные ключевые аргументы для `requests.request`. Returns: @@ -284,19 +281,18 @@ def post(self, url, data=None, timeout=default_timeout, *args, **kwargs) -> Unio :class:`yandex_music.exceptions.YandexMusicError`: Базовое исключение библиотеки. """ result = self._request_wrapper( - 'POST', url, headers=self.headers, proxies=self.proxies, data=data, timeout=timeout, *args, **kwargs + 'POST', url, headers=self.headers, proxies=self.proxies, data=data, timeout=timeout, **kwargs ) return self._parse(result).get_result() - def retrieve(self, url, timeout=default_timeout, *args, **kwargs) -> bytes: + def retrieve(self, url, timeout=default_timeout, **kwargs) -> bytes: """Отправка GET запроса и получение содержимого без обработки (парсинга). Args: url (:obj:`str`): Адрес для запроса. timeout (:obj:`int` | :obj:`float`): Используется как время ожидания ответа от сервера вместо указанного при создании пула. - *args: Произвольные аргументы для `requests.request`. **kwargs: Произвольные ключевые аргументы для `requests.request`. Returns: @@ -305,9 +301,9 @@ def retrieve(self, url, timeout=default_timeout, *args, **kwargs) -> bytes: Raises: :class:`yandex_music.exceptions.YandexMusicError`: Базовое исключение библиотеки. """ - return self._request_wrapper('GET', url, proxies=self.proxies, timeout=timeout, *args, **kwargs) + return self._request_wrapper('GET', url, proxies=self.proxies, timeout=timeout, **kwargs) - def download(self, url, filename, timeout=default_timeout, *args, **kwargs) -> None: + def download(self, url, filename, timeout=default_timeout, **kwargs) -> None: """Отправка запроса на получение содержимого и его запись в файл. Args: @@ -315,12 +311,11 @@ def download(self, url, filename, timeout=default_timeout, *args, **kwargs) -> N filename (:obj:`str`): Путь и(или) название файла вместе с расширением. timeout (:obj:`int` | :obj:`float`): Используется как время ожидания ответа от сервера вместо указанного при создании пула. - *args: Произвольные аргументы для `requests.request`. **kwargs: Произвольные ключевые аргументы для `requests.request`. Raises: :class:`yandex_music.exceptions.YandexMusicError`: Базовое исключение библиотеки. """ - result = self.retrieve(url, timeout=timeout, *args, *kwargs) + result = self.retrieve(url, timeout=timeout, **kwargs) with open(filename, 'wb') as f: f.write(result) diff --git a/yandex_music/utils/request_async.py b/yandex_music/utils/request_async.py index 23def98b..84970a55 100644 --- a/yandex_music/utils/request_async.py +++ b/yandex_music/utils/request_async.py @@ -2,30 +2,28 @@ # THIS IS AUTO GENERATED COPY OF client.py. DON'T EDIT IN BY HANDS # #################################################################### -import re -import logging -import keyword - -from typing import TYPE_CHECKING, Optional, Union - # Не используется ujson из-за отсутствия в нём object_hook'a # Отправка вообще application/x-www-form-urlencoded, а не JSON'a # https://github.com/psf/requests/blob/master/requests/models.py#L508 +import asyncio import json +import keyword +import logging +import re +from typing import TYPE_CHECKING, Optional, Union -import asyncio -import aiohttp import aiofiles +import aiohttp -from yandex_music.utils.response import Response from yandex_music.exceptions import ( - UnauthorizedError, BadRequestError, NetworkError, - YandexMusicError, - TimedOutError, NotFoundError, + TimedOutError, + UnauthorizedError, + YandexMusicError, ) +from yandex_music.utils.response import Response if TYPE_CHECKING: from yandex_music import Client @@ -178,18 +176,18 @@ def _parse(self, json_data: bytes) -> Optional[Response]: decoded_s = json_data.decode('utf-8') data = json.loads(decoded_s, object_hook=Request._object_hook) - except UnicodeDecodeError: + except UnicodeDecodeError as e: logging.getLogger(__name__).debug('Logging raw invalid UTF-8 response:\n%r', json_data) - raise YandexMusicError('Server response could not be decoded using UTF-8') - except (AttributeError, ValueError): - raise YandexMusicError('Invalid server response') + raise YandexMusicError('Server response could not be decoded using UTF-8') from e + except (AttributeError, ValueError) as e: + raise YandexMusicError('Invalid server response') from e if data.get('result') is None: data = {'result': data, 'error': data.get('error'), 'error_description': data.get('error_description')} return Response.de_json(data, self.client) - async def _request_wrapper(self, *args, **kwargs): + async def _request_wrapper(self, *args, **kwargs): # noqa: C901 """Обёртка над запросом библиотеки `aiohttp`. Note: @@ -205,7 +203,8 @@ async def _request_wrapper(self, *args, **kwargs): Raises: :class:`yandex_music.exceptions.TimedOutError`: При превышении времени ожидания. - :class:`yandex_music.exceptions.UnauthorizedError`: При невалидном токене, долгом ожидании прямой ссылки на файл. + :class:`yandex_music.exceptions.UnauthorizedError`: При невалидном токене, + долгом ожидании прямой ссылки на файл. :class:`yandex_music.exceptions.BadRequestError`: При неправильном запросе. :class:`yandex_music.exceptions.NetworkError`: При проблемах с сетью. """ @@ -223,10 +222,10 @@ async def _request_wrapper(self, *args, **kwargs): async with aiohttp.request(*args, **kwargs) as _resp: resp = _resp content = await resp.content.read() - except asyncio.TimeoutError: - raise TimedOutError() + except asyncio.TimeoutError as e: + raise TimedOutError from e except aiohttp.ClientError as e: - raise NetworkError(e) + raise NetworkError(e) from e if 200 <= resp.status <= 299: return content @@ -239,20 +238,20 @@ async def _request_wrapper(self, *args, **kwargs): if resp.status in (401, 403): raise UnauthorizedError(message) - elif resp.status == 400: + if resp.status == 400: raise BadRequestError(message) - elif resp.status == 404: + if resp.status == 404: raise NotFoundError(message) - elif resp.status in (409, 413): + if resp.status in (409, 413): raise NetworkError(message) - elif resp.status == 502: + if resp.status == 502: raise NetworkError('Bad Gateway') - else: - raise NetworkError(f'{message} ({resp.status}): {content}') + + raise NetworkError(f'{message} ({resp.status}): {content}') async def get( - self, url: str, params: dict = None, timeout: Union[int, float] = default_timeout, *args, **kwargs + self, url: str, params: dict = None, timeout: Union[int, float] = default_timeout, **kwargs ) -> Union[dict, str]: """Отправка GET запроса. @@ -261,7 +260,6 @@ async def get( params (:obj:`str`): GET параметры для запроса. timeout (:obj:`int` | :obj:`float`): Используется как время ожидания ответа от сервера вместо указанного при создании пула. - *args: Произвольные аргументы для `aiohttp.request`. **kwargs: Произвольные ключевые аргументы для `aiohttp.request`. Returns: @@ -271,12 +269,12 @@ async def get( :class:`yandex_music.exceptions.YandexMusicError`: Базовое исключение библиотеки. """ result = await self._request_wrapper( - 'GET', url, params=params, headers=self.headers, proxy=self.proxy_url, timeout=timeout, *args, **kwargs + 'GET', url, params=params, headers=self.headers, proxy=self.proxy_url, timeout=timeout, **kwargs ) return self._parse(result).get_result() - async def post(self, url, data=None, timeout=default_timeout, *args, **kwargs) -> Union[dict, str]: + async def post(self, url, data=None, timeout=default_timeout, **kwargs) -> Union[dict, str]: """Отправка POST запроса. Args: @@ -284,7 +282,6 @@ async def post(self, url, data=None, timeout=default_timeout, *args, **kwargs) - data (:obj:`str`): POST тело запроса. timeout (:obj:`int` | :obj:`float`): Используется как время ожидания ответа от сервера вместо указанного при создании пула. - *args: Произвольные аргументы для `aiohttp.request`. **kwargs: Произвольные ключевые аргументы для `aiohttp.request`. Returns: @@ -294,19 +291,18 @@ async def post(self, url, data=None, timeout=default_timeout, *args, **kwargs) - :class:`yandex_music.exceptions.YandexMusicError`: Базовое исключение библиотеки. """ result = await self._request_wrapper( - 'POST', url, headers=self.headers, proxy=self.proxy_url, data=data, timeout=timeout, *args, **kwargs + 'POST', url, headers=self.headers, proxy=self.proxy_url, data=data, timeout=timeout, **kwargs ) return self._parse(result).get_result() - async def retrieve(self, url, timeout=default_timeout, *args, **kwargs) -> bytes: + async def retrieve(self, url, timeout=default_timeout, **kwargs) -> bytes: """Отправка GET запроса и получение содержимого без обработки (парсинга). Args: url (:obj:`str`): Адрес для запроса. timeout (:obj:`int` | :obj:`float`): Используется как время ожидания ответа от сервера вместо указанного при создании пула. - *args: Произвольные аргументы для `aiohttp.request`. **kwargs: Произвольные ключевые аргументы для `aiohttp.request`. Returns: @@ -315,9 +311,9 @@ async def retrieve(self, url, timeout=default_timeout, *args, **kwargs) -> bytes Raises: :class:`yandex_music.exceptions.YandexMusicError`: Базовое исключение библиотеки. """ - return await self._request_wrapper('GET', url, proxy=self.proxy_url, timeout=timeout, *args, **kwargs) + return await self._request_wrapper('GET', url, proxy=self.proxy_url, timeout=timeout, **kwargs) - async def download(self, url, filename, timeout=default_timeout, *args, **kwargs) -> None: + async def download(self, url, filename, timeout=default_timeout, **kwargs) -> None: """Отправка запроса на получение содержимого и его запись в файл. Args: @@ -325,12 +321,11 @@ async def download(self, url, filename, timeout=default_timeout, *args, **kwargs filename (:obj:`str`): Путь и(или) название файла вместе с расширением. timeout (:obj:`int` | :obj:`float`): Используется как время ожидания ответа от сервера вместо указанного при создании пула. - *args: Произвольные аргументы для `aiohttp.request`. **kwargs: Произвольные ключевые аргументы для `aiohttp.request`. Raises: :class:`yandex_music.exceptions.YandexMusicError`: Базовое исключение библиотеки. """ - result = await self.retrieve(url, timeout=timeout, *args, *kwargs) + result = await self.retrieve(url, timeout=timeout, **kwargs) async with aiofiles.open(filename, 'wb') as f: await f.write(result) diff --git a/yandex_music/utils/sign_request.py b/yandex_music/utils/sign_request.py index 78b51166..358c317e 100644 --- a/yandex_music/utils/sign_request.py +++ b/yandex_music/utils/sign_request.py @@ -1,13 +1,12 @@ -from typing import Union -from dataclasses import dataclass +import base64 import datetime -import hmac import hashlib -import base64 +import hmac +from dataclasses import dataclass +from typing import Union from yandex_music.utils.convert_track_id import convert_track_id_to_number - DEFAULT_SIGN_KEY = 'p93jhgh689SBReK6ghtw62' """:obj:`str`: Ключ для подписи из Android приложения.""" diff --git a/yandex_music/video.py b/yandex_music/video.py index d88df952..0f7cd2e4 100644 --- a/yandex_music/video.py +++ b/yandex_music/video.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Optional, List, Union +from typing import TYPE_CHECKING, List, Optional, Union from yandex_music import YandexMusicObject from yandex_music.utils import model @@ -74,7 +74,7 @@ def de_list(cls, data: list, client: 'Client') -> List['Video']: if not cls.is_valid_model_data(data, array=True): return [] - videos = list() + videos = [] for video in data: videos.append(cls.de_json(video, client))