-
Notifications
You must be signed in to change notification settings - Fork 2k
importsource: Only register listener if configured #6297
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
base: master
Are you sure you want to change the base?
Conversation
|
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 Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
98c3efe to
6f75310
Compare
|
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. |
There was a problem hiding this 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this 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_removedandimport_task_choicelisteners 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.
and remove the now redundant config sanity check in suggest_removal().
6f75310 to
82bd488
Compare
|
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. |
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.