Skip to content

typing: type beets core and refactor do_query - #6935

Closed
snejus wants to merge 4 commits into
typing-type-command-handlersfrom
type-and-refactor-do-query
Closed

typing: type beets core and refactor do_query#6935
snejus wants to merge 4 commits into
typing-type-command-handlersfrom
type-and-refactor-do-query

Conversation

@snejus

@snejus snejus commented Aug 18, 2026

Copy link
Copy Markdown
Member

Part of #6924.

  • Types are added to the entire beets core, i.e. beets folder.

  • The shared do_query helper is removed where query/selection logic is moved into each command's own item- or album-specific path, including modify, move, remove, update, write, and beetsplug/edit.

  • Architecturally, this shifts the CLI commands away from a generic shared query abstraction toward model-specific flows built around Item, Album, and AlbumOrItem. That makes each command's control flow more explicit and easier to type correctly.

  • The main payoff is better type safety: input_select_objects now works with Sequence[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.remove contract.

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

Copilot AI lite review requested due to automatic review settings August 18, 2026 09:14
@snejus
snejus requested review from a team and semohr as code owners August 18, 2026 09:14
@github-actions

Copy link
Copy Markdown

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

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.95215% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.88%. Comparing base (74d1233) to head (f5a949f).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beets/ui/__init__.py 89.79% 2 Missing and 3 partials ⚠️
beets/ui/commands/update.py 28.57% 4 Missing and 1 partial ⚠️
beets/autotag/distance.py 75.00% 2 Missing and 2 partials ⚠️
beets/ui/commands/move.py 84.00% 4 Missing ⚠️
beets/events.py 0.00% 3 Missing ⚠️
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     
Files with missing lines Coverage Δ
beets/__init__.py 62.50% <100.00%> (ø)
beets/autotag/__init__.py 71.42% <100.00%> (+2.19%) ⬆️
beets/autotag/match.py 88.09% <ø> (ø)
beets/context.py 100.00% <100.00%> (ø)
beets/dbcore/db.py 94.45% <100.00%> (ø)
beets/library/__init__.py 100.00% <100.00%> (ø)
beets/library/models.py 87.22% <100.00%> (+0.01%) ⬆️
beets/logging.py 95.23% <100.00%> (ø)
beets/metadata_plugins.py 91.01% <100.00%> (ø)
beets/plugins.py 89.56% <100.00%> (ø)
... and 22 more

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_query and 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.

Comment thread beets/autotag/distance.py Outdated
Comment thread beets/ui/commands/modify.py
Comment thread beets/ui/commands/remove.py Outdated
Comment thread beets/ui/commands/remove.py Outdated
Comment thread beets/ui/commands/write.py
Comment thread beets/test/fixtures.py
@snejus
snejus force-pushed the typing-type-command-handlers branch from 5ed97bd to 74d1233 Compare August 18, 2026 09:56
@snejus
snejus force-pushed the type-and-refactor-do-query branch 2 times, most recently from 9c35cd5 to e538623 Compare August 18, 2026 18:18
@snejus
snejus force-pushed the type-and-refactor-do-query branch from e538623 to f5a949f Compare August 18, 2026 18:50
@snejus
snejus requested a lite review from Copilot August 18, 2026 18:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 update now build items and call update_items even when query match nothing. Before do_query raised 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))

Comment thread beets/ui/commands/move.py
Comment on lines +101 to 107
selected_objs = ui.input_select_objects(
f"Really {act}",
objs,
lambda o: show_path_changes(
[(o.path, o.destination(basedir=dest))]
),
)
Comment thread beets/util/extension.py
Comment on lines 139 to +143
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)
@snejus

snejus commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

Replaced by #6941 and #6942.

@snejus snejus closed this Aug 18, 2026
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