typing: add types to beets.util and beets.test.helper#6805
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 @@
## speed-up-tests #6805 +/- ##
==================================================
- Coverage 74.98% 74.80% -0.19%
==================================================
Files 163 163
Lines 20966 20967 +1
Branches 3302 3302
==================================================
- Hits 15721 15684 -37
- Misses 4486 4527 +41
+ Partials 759 756 -3
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
PR try make first step toward pathlib.Path migration by adding typing to beets.util and beets.test.helper, plus split test helper behavior into smaller mixins (PathsMixin, ImporterMixin).
Changes:
- Add tighter type hints in
beets/util/__init__.pyand widen some path-accepting APIs toPathLike. - Refactor
beets/test/helper.pyinto smaller mixins and update helper methods to normalize path handling. - Adjust importer test helper setup to use typed
template(...)forlib.path_formats.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| beets/util/init.py | Type annotations on filesystem helpers; small behavior-neutral cleanup in move() typing comments. |
| beets/test/helper.py | New mixins + typing; path normalization changes in helpers; importer helper setup updated. |
semohr
left a comment
There was a problem hiding this comment.
Looks good from my perspective.
Consider adding the files to the optin stricter mypy config.
74a0002 to
0375672
Compare
a835cc4 to
e26ee18
Compare
I tried adding them: diff --git a/setup.cfg b/setup.cfg
index 01971c01d..259e8a5c0 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -55,6 +55,12 @@ check_untyped_defs = true
disallow_untyped_decorators = true
check_untyped_defs = true
+[[mypy-beets.utils]]
+strict = true
+
+[[mypy-beets.test.helper]]
+strict = true
+
[[mypy-beetsplug.musicbrainz]]
strict = trueAnd ran |
e26ee18 to
f2f5997
Compare
| if task.candidates: | ||
| if choice == importer.Action.APPLY: | ||
| return task.candidates[0] # type: ignore[return-value] | ||
| if isinstance(choice, int): | ||
| return task.candidates[choice - 1] # type: ignore[return-value] | ||
|
|
||
| assert not isinstance(choice, int), f"Invalid choice: {choice}" | ||
| return choice |
| def _make_album_match( | ||
| self, | ||
| artist: str, | ||
| album: str, | ||
| tracks: int, | ||
| distance: int = 0, | ||
| missing: int = 0, | ||
| ) -> AlbumInfo: |
f2f5997 to
7716532
Compare
- Removing the coverage omit configuration exposed unused branches, helpers, and fixtures across the test suite. - Delete that redundant logic and simplify affected tests while preserving their behavior.
7716532 to
9232a66
Compare
Maybe using My idea here was just to have future changes require stricter rules for these files as they are typed properly right now. |
I've started working on migrating the codebase to
pathlib.Pathand this is the very first step: fully typebeets.utilandbeets.test.helper. Next, I will me migrating tests to usepathlib.Path.Extracts shared path/temp-directory behavior into
PathsMixin, and splits import-specific test setup intoImporterMixin. This makesbeets.test.helpermore modular and gives test helpers a clearer inheritance structure.Updates
TestHelperand import helpers to use those smaller mixins, while keeping existing test behavior intact. The main architectural effect is better separation between core test setup, filesystem helpers, and importer-specific utilities.Tightens typing across
beets.test.helperandbeets.util, especially around path handling.beets.utilnow accepts a broader set of path types throughPathLike/AnyPath, which reduces friction betweenbytes,str, andPathusage.Aligns helper internals with the typed interfaces by normalizing path handling in methods like
touch, using typedtemplate(...)entries for importer path formats, and fixing a few return-type/inheritance edge cases.High-level impact: this is mainly a typing and test-infrastructure cleanup. It improves maintainability and type-checker accuracy without changing production architecture or intended runtime behavior.