Skip to content

Conversation

@JOJ0
Copy link
Member

@JOJ0 JOJ0 commented Jan 17, 2026

Description

Does not fix anything, just corrects what the plugin is supposed to do. If the feature is not enabled, registering a listener is not required.

Added 2 new tests that prove this is the case.

  • Documentation.
  • Changelog. Not required since it is a new and unreleased plugin that has a changelog entry already.
  • Tests.

@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.

@codecov
Copy link

codecov bot commented Jan 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.72%. Comparing base (6c2c460) to head (82bd488).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6297   +/-   ##
=======================================
  Coverage   68.72%   68.72%           
=======================================
  Files         138      138           
  Lines       18556    18557    +1     
  Branches     3062     3063    +1     
=======================================
+ Hits        12752    12753    +1     
  Misses       5153     5153           
  Partials      651      651           
Files with missing lines Coverage Δ
beetsplug/importsource.py 69.56% <100.00%> (+0.44%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JOJ0 JOJ0 force-pushed the importsource_listener branch 2 times, most recently from 98c3efe to 6f75310 Compare January 17, 2026 08:16
@JOJ0 JOJ0 marked this pull request as ready for review January 17, 2026 08:23
@JOJ0 JOJ0 requested a review from a team as a code owner January 17, 2026 08:23
Copilot AI review requested due to automatic review settings January 17, 2026 08:23
@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 - I've found 1 issue, and left some high level feedback:

  • When checking self.config["suggest_removal"] in __init__, consider using the appropriate config API (e.g. .get(bool) / .as_bool()) instead of relying on the truthiness of the ConfigView itself to make the intent explicit and avoid subtle behavior changes if the config layer changes.
  • The tests access plugins._instances[0] which assumes a specific plugin ordering and a single instance; if possible, consider narrowing this to the concrete plugin instance more directly (e.g. by type or name) to make the tests more robust to future changes in plugin loading.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When checking `self.config["suggest_removal"]` in `__init__`, consider using the appropriate config API (e.g. `.get(bool)` / `.as_bool()`) instead of relying on the truthiness of the ConfigView itself to make the intent explicit and avoid subtle behavior changes if the config layer changes.
- The tests access `plugins._instances[0]` which assumes a specific plugin ordering and a single instance; if possible, consider narrowing this to the concrete plugin instance more directly (e.g. by type or name) to make the tests more robust to future changes in plugin loading.

## Individual Comments

### Comment 1
<location> `beetsplug/importsource.py:29-30` </location>
<code_context>
-        self.register_listener(
-            "import_task_choice", self.prevent_suggest_removal
-        )
+        # Only register removal suggestion listeners if the feature is enabled
+        if self.config["suggest_removal"]:
+            # In order to stop future removal suggestions for an album we keep
+            # track of `mb_albumid`s in this set.
</code_context>

<issue_to_address>
**issue (bug_risk):** Guard should likely use a boolean value from config instead of relying on truthiness of the config view.

In beets, `self.config["suggest_removal"]` is a `ConfigView`, which is always truthy regardless of the configured boolean. As a result, this condition will always pass and the listeners will be registered even when the feature is disabled. Use the underlying boolean value instead (e.g. `self.config["suggest_removal"].get(bool)` or `.as_bool()`).
</issue_to_address>

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
Contributor

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 PR optimizes the importsource plugin by conditionally registering event listeners only when the suggest_removal feature is enabled. This follows the principle of not registering unnecessary event handlers when functionality is disabled.

Changes:

  • Modified plugin initialization to conditionally register item_removed and import_task_choice listeners based on configuration
  • Added comprehensive tests to verify listener registration behavior in both enabled and disabled states

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
beetsplug/importsource.py Wrapped listener registration and attribute initialization in a conditional block that checks the suggest_removal config value
test/plugins/test_importsource.py Added new test class with two tests verifying that listeners and attributes are only created when the feature is enabled

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JOJ0 JOJ0 marked this pull request as draft January 17, 2026 08:26
JOJ0 added 2 commits January 17, 2026 09:29
and remove the now redundant config sanity check in suggest_removal().
@JOJ0 JOJ0 force-pushed the importsource_listener branch from 6f75310 to 82bd488 Compare January 17, 2026 08:30
@JOJ0 JOJ0 marked this pull request as ready for review January 17, 2026 08:49
@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.

@JOJ0 JOJ0 added the plugin Pull requests that are plugins related label Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin Pull requests that are plugins related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants