typing: add missing types to beets.importer#6711
Open
snejus wants to merge 6 commits into
Open
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 @@
## master #6711 +/- ##
=======================================
Coverage 75.57% 75.58%
=======================================
Files 162 162
Lines 20806 20815 +9
Branches 3292 3291 -1
=======================================
+ Hits 15725 15733 +8
- Misses 4306 4307 +1
Partials 775 775
🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
grug see PR try make importer more typed. goal good: less guess, more clear pipe flow. but grug also see one bug where plugin return shape now break old contract.
Changes:
- add many type hints across importer tasks/session/stages, and pipeline typing
- make importer config mutation use confuse
.set(...)/.get(...) - small cleanup in plugins event typing and some path bytes handling
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| beetsplug/fetchart.py | guard prune call when candidate path maybe None |
| beetsplug/convert.py | small pipeline call simplification |
| beets/util/pipeline.py | add typing + generic Pipeline shape + adjust parallel run structure |
| beets/plugins.py | add overload for typed send() event contract |
| beets/importer/tasks.py | add types, safer config access, adjust archive extract bytes handling, and change import_task_created dispatch path |
| beets/importer/state.py | add types for ImportState and context manager methods |
| beets/importer/stages.py | add stage message type aliases and stage function return types |
| beets/importer/session.py | add types + switch config mutation to confuse .set(...) / .get(...) |
| beets/dbcore/db.py | make LazyConvertDict implement Mapping for typing |
| .git-blame-ignore-revs | ignore rev for this typing-only-ish change set |
83eece5 to
16998ab
Compare
16998ab to
2de70c5
Compare
ff1c9e7 to
b19cc73
Compare
2de70c5 to
dbe9a86
Compare
35acaac to
b148c94
Compare
Previously, we had
`iconfig: dict[str, confuse.Subview] = dict(config)`
Since this was just a dictionary, explicit assignments like
`iconfig["copy"] = False` replaced `Subview` with the value:
```
iconfig
{
'autotag': <Subview: import.autotag>,
'bell': <Subview: import.bell>,
'copy': False,
...
}
```
Thus, keys overriden by `set_config` lost their `Subview` type, where
methods like `.get` were lost. This ultimately resulted in the following
type:
`ImportSession.config: dict[str, confuse.Subview | str | bool]`
This branch never gets run, and it would cause a TypeError if it did.
dirs is always provided as a list of bytes.
b148c94 to
9ffe742
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change tightens typing across the importer pipeline, mainly in
beets.importer.session,beets.importer.stages,beets.importer.tasks,beets.importer.state, andbeets.util.pipeline.Architecturally, it makes the importer's core flow more explicit:
Pipelineimport_task_creatednow has a typed contractA small but important part of the change is switching importer config handling to work with
confuseviews more safely, using.set(...)and.get(...)instead of replacing values directly. This keeps config mutation aligned with the config system instead of treating it like a plain dict.There are also a few correctness-oriented fixes uncovered while adding types, such as:
Nonein places that already behaved that way implicitlyHigh-level impact: no feature change to importer behavior is intended. The main benefit is a clearer, more strongly typed importer architecture that is easier to reason about, safer to refactor, and better at catching edge cases during development.