Skip to content

Minor improvements to deezer plugin typing. #5814

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

semohr
Copy link
Contributor

@semohr semohr commented Jun 2, 2025

Description

Added some more typehints to deezer plugin.

I know, it is properly not used much and we don't even have test for the deezer plugin but I want to make this a bit more maintainable, mainly to prepare for #5787 and make migration a bit easier.

@Copilot Copilot AI review requested due to automatic review settings June 2, 2025 11:24
Copy link

github-actions bot commented Jun 2, 2025

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request enhances the Deezer plugin by adding and refining type hints to improve code maintainability and prepare for an upcoming migration.

  • Updated function signatures with type hints (e.g. commands, track_for_id, _get_track, _search_api).
  • Re-ordered and consolidated API URLs and fetch_data implementation.
  • Adjusted imports and type annotations across both beetsplug/deezer.py and beets/plugins.py.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
beetsplug/deezer.py Added type hints, updated function parameters/docstrings, and moved API URL definitions.
beets/plugins.py Updated _search_api type hints for query_type using Literal.
Comments suppressed due to low confidence (1)

beetsplug/deezer.py:149

  • The docstring for track_for_id still references a track_data parameter that was removed from the function signature. Please update the documentation to reflect the current parameters.
    :param track_data: (Optional) Simplified track object dict. May be provided instead of ``track_id`` to avoid unnecessary API calls.

semohr added a commit that referenced this pull request Jun 11, 2025
## Description

Added some more typehints to the spotify plugin. Also added a method to
get the tokenfile and changed to logic for the handle_response to use
`requests.request`.

This is done mainly to prepare for
#5787, see also
#5814
Copy link
Member

@snejus snejus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to isolate method moves into a separate commit? It's a bit complicated to see the relevant changes when the entire method implementations are red and green 😅


class DeezerPlugin(MetadataSourcePlugin, BeetsPlugin):

class DeezerPlugin(MetadataSourcePlugin[Response], BeetsPlugin):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we define a deezer-specific Response?

Copy link
Contributor Author

@semohr semohr Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimally yes! Adding one should be relative straight forward, this Response here only defines an id attribute.

I did not want to create an deezer account to look at the api documentation tbh. But maybe someone else wants to tackle this.

@@ -737,7 +738,7 @@ def track_url(self) -> str:
@abc.abstractmethod
def _search_api(
self,
query_type: str,
query_type: Literal["album", "track"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest defining

QueryType = Literal["album", "track"]

And import it in beetsplug/deezer.py instead of defining it in multiple places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah something alike would be preferable, I might revisit it once we merge the metadata plugin PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I just noticed that the deezer api can take other query types, thus defining it globally might intertwine the types more the necessary. E.g. for deezer the complete type-hint would be:

Literal[
    "album",
    "track",
    "artist",
    "history",
    "playlist",
    "podcast",
    "radio",
    "user",
],

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I don't think the interface/abstract definition should be coupled to any specific child/plugin implementation.

We know that this method is only ever called with values album and track, so I think we should just add these two in the type definition.

Copy link
Contributor Author

@semohr semohr Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the main definition that is the case i.e. in the MetadatasourcePlugin the method only supports album and track.

It should be fine if the specific plugins support more than we need from the core perspective. Just added it here to indicate that (in theory) the deezer api supports these endpoint and removed the comment regarding the endpoints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants