typing: type beets core and refactor do_query - #6935
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❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## typing-type-command-handlers #6935 +/- ##
================================================================
- Coverage 76.08% 75.88% -0.20%
================================================================
Files 164 163 -1
Lines 21353 21368 +15
Branches 3333 3329 -4
================================================================
- Hits 16247 16216 -31
- Misses 4317 4364 +47
+ Partials 789 788 -1
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
PR add many type hints across beets core, and rip out shared do_query helper so each CLI command do its own item vs album flow. grug like clearer flow, but big change, many place for bug hide.
Changes:
- Add/adjust type annotations across core modules, utilities, and command layer.
- Remove
beets.ui.commands.utils.do_queryand refactor commands to query items/albums directly. - Update tests to match new command function shapes and typing changes.
Reviewed changes
Copilot reviewed 41 out of 41 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/ui/commands/test_utils.py | Remove tests for deleted do_query helper. |
| test/ui/commands/test_update.py | Update tests to pass explicit item list into update_items. |
| test/ui/commands/test_remove.py | Update tests for split remove_items / remove_albums APIs. |
| test/ui/commands/test_move.py | Update tests for split move_items / move_albums APIs and dest encoding. |
| test/test_importer.py | Update tag log tests to use shared test helper lib fixture. |
| beetsplug/edit.py | Switch edit selection to lib.items / lib.albums directly. |
| beets/util/units.py | Add type annotations to unit formatting helpers. |
| beets/util/pipeline.py | Tighten typing in pipeline queue invalidation + doctest hints. |
| beets/util/m3u.py | Add typing for playlist path/contents and method returns. |
| beets/util/extension.py | Make fix_extension return bytes consistently. |
| beets/util/config.py | Type UnknownPairError constructor args. |
| beets/ui/commands/write.py | Remove do_query usage; use direct lib.items query. |
| beets/ui/commands/version.py | Add return type to version printer. |
| beets/ui/commands/utils.py | Delete do_query helper module. |
| beets/ui/commands/update.py | Refactor update_items to accept iterable of Items; type annotations. |
| beets/ui/commands/stats.py | Add typing to stats command entry. |
| beets/ui/commands/remove.py | Split item vs album removal paths; add shared selection helper. |
| beets/ui/commands/move.py | Split item vs album move paths; add shared move core helper. |
| beets/ui/commands/modify.py | Split item vs album modify paths; refactor modify core helper. |
| beets/ui/commands/list.py | Type list_items; avoid shadowing album name; adjust usage string building. |
| beets/ui/commands/help.py | Add typing and assert parser type for help lookup. |
| beets/ui/commands/fields.py | Add typing for sqlite rows + inner helpers. |
| beets/ui/commands/config.py | Type config_edit callback signature. |
| beets/ui/commands/completion.py | Add typing and clean up variable names in completion generation. |
| beets/ui/commands/init.py | Add typing for deprecated import shim and default command list. |
| beets/ui/init.py | Add lots of typing for UI helpers, parsers, and object selection. |
| beets/test/helper.py | Type fixture fields and __init__ return. |
| beets/test/fixtures.py | Type fixture models + dummy backend init. |
| beets/test/_common.py | Add typing to common test helpers and import session helper. |
| beets/plugins.py | Type plugin error + plugin base init. |
| beets/metadata_plugins.py | Type contextmanager return. |
| beets/logging.py | Tighten logger/formatter typing and signatures. |
| beets/library/models.py | Refactor remove contract to typed abstract-ish API via _remove. |
| beets/library/init.py | Type deprecated import shim return. |
| beets/events.py | Build ALL_EVENTS from EventType typing metadata. |
| beets/dbcore/db.py | Add return typing for add and widen formatted arg type. |
| beets/context.py | Type context manager return. |
| beets/autotag/match.py | Add explicit None return on helper. |
| beets/autotag/distance.py | Tighten typing on comparison/math-like methods. |
| beets/autotag/init.py | Type deprecated import shim return. |
| beets/init.py | Type deprecated import shim return. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
5ed97bd to
74d1233
Compare
9c35cd5 to
e538623
Compare
This allows to define a proper return type for input_select_objects.
e538623 to
f5a949f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 42 out of 42 changed files in this pull request and generated 2 comments.
Suppressed comments (1)
beets/ui/commands/update.py:166
- grug see
updatenow builditemsand callupdate_itemseven when query match nothing. Beforedo_queryraised UserError. Now command silently do nothing. grug think keep old user-visible error.
if opts.album:
items = [i for a in lib.albums(args) for i in a.items()]
else:
items = list(lib.items(args))
| selected_objs = ui.input_select_objects( | ||
| f"Really {act}", | ||
| objs, | ||
| lambda o: show_path_changes( | ||
| [(o.path, o.destination(basedir=dest))] | ||
| ), | ||
| ) |
| util.copy(bytes(path), bytes(new_path)) | ||
| else: | ||
| if logger: | ||
| logger.info("Import file with matching format to original target") | ||
| return new_path | ||
| return os.fsencode(new_path) |
Part of #6924.
Types are added to the entire beets core, i.e.
beetsfolder.The shared
do_queryhelper is removed where query/selection logic is moved into each command's own item- or album-specific path, includingmodify,move,remove,update,write, andbeetsplug/edit.Architecturally, this shifts the CLI commands away from a generic shared query abstraction toward model-specific flows built around
Item,Album, andAlbumOrItem. That makes each command's control flow more explicit and easier to type correctly.The main payoff is better type safety:
input_select_objectsnow works withSequence[AlbumOrItem], and commands can return and operate on the right model type without going through a loosely typed helper.Related typing cleanup across core modules supports this refactor, including clearer method signatures and a more explicit
LibModel.removecontract.High-level impact for reviewers: behavior should stay mostly the same, but the command layer is now simpler to follow, less coupled to shared query plumbing, and better prepared for stronger static typing.