Skip to content

Conversation

@cp89-cyber
Copy link

@cp89-cyber cp89-cyber commented Sep 13, 2025

Summary

  • fall back to stdlib JSONDecodeError if requests lacks it
  • catch JSONDecodeError via shared alias in lyrics plugin

Testing

  • - pre-commit run --files beetsplug/lyrics.py
  • - `pytest test/plugins/test_lyrics.py test/plugins/lyrics_pages.py

`

@cp89-cyber cp89-cyber requested a review from a team as a code owner September 13, 2025 23:49
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 13, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Introduce a compatibility fallback for JSONDecodeError when using older versions of requests and update the lyrics plugin to use this alias in its exception handling.

Class diagram for updated exception handling in lyrics plugin

classDiagram
class LyricsPlugin {
    +post_json(url: str, params: JSONDict | None = None, **kwargs)
    +handle_request() Iterator[None]
}
class NotFoundError {
    <<inherits>> requests.exceptions.HTTPError
}
class JSONDecodeError

LyricsPlugin --|> NotFoundError
LyricsPlugin ..> JSONDecodeError : uses
Loading

Flow diagram for JSONDecodeError fallback logic

flowchart TD
    A["Check if requests.exceptions has JSONDecodeError"] -->|Yes| B["Use requests.exceptions.JSONDecodeError"]
    A -->|No| C["Use json.JSONDecodeError from stdlib"]
    B & C --> D["Assign to shared alias JSONDecodeError"]
Loading

File-Level Changes

Change Details Files
Define a JSONDecodeError alias that falls back to the stdlib exception
  • Add a JSONDecodeError variable using getattr on requests.exceptions
  • Use json.JSONDecodeError as the default fallback
beetsplug/lyrics.py
Update exception handling to use the new JSONDecodeError alias
  • Change the except clause from requests.JSONDecodeError to JSONDecodeError
beetsplug/lyrics.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions
Copy link

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

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Move the JSONDecodeError alias closer to the top of the module (with the other imports) to improve readability.
  • Consider using a try/except import block for JSONDecodeError rather than getattr for a more conventional fallback pattern.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Move the JSONDecodeError alias closer to the top of the module (with the other imports) to improve readability.
- Consider using a try/except import block for JSONDecodeError rather than getattr for a more conventional fallback pattern.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

Thanks for addressing this! I think, we'd rather keep using requests.JSONDecodeError unconditionally in lyrics.py and instead update the requests dependency requirement to ensure that users do not install outdated versions.

Would you be happy to do so?

  1. Update requests version requirement to require the version that JSONDecodeError was introduced as the minimum (I think it was >=2.27.0).
  2. Run uv tool run poetry<2 update requests

@cp89-cyber cp89-cyber closed this by deleting the head repository Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants