Skip to content

typing: make albums_in_dir, sorted_walk and other utils generic over AnyStr#6806

Open
snejus wants to merge 2 commits into
masterfrom
make-bytes-utils-generic-over-anystr
Open

typing: make albums_in_dir, sorted_walk and other utils generic over AnyStr#6806
snejus wants to merge 2 commits into
masterfrom
make-bytes-utils-generic-over-anystr

Conversation

@snejus

@snejus snejus commented Jun 30, 2026

Copy link
Copy Markdown
Member

Fixes #6808

  • This change makes the path-handling utilities is_hidden, sorted_walk, unique_path, remux_mpeglayer3_wav and albums_in_dir work with both str and bytes paths instead of assuming bytes everywhere.

  • Architecturally, the PR moves these helpers toward a single generic path flow using AnyStr, so callers can stay in their native path type while the utilities preserve that type through traversal, filtering, and hidden-file checks.

  • In albums_in_dir, the multi-disc detection logic was updated to support both string and byte paths by splitting regex handling into str and bytes variants while keeping the existing album-collapsing behavior the same.

  • High-level impact: this reduces path-conversion friction, improves typing consistency across importer and util code, and makes the filesystem helpers easier to reuse as the codebase continues moving away from bytes-only assumptions.

Copilot AI review requested due to automatic review settings June 30, 2026 16:46
@snejus snejus requested a review from a team as a code owner June 30, 2026 16:46
@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 Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.61538% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.84%. Comparing base (8ddae79) to head (db2e2fc).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beets/util/extension.py 70.00% 1 Missing and 2 partials ⚠️
beets/importer/tasks.py 89.47% 1 Missing and 1 partial ⚠️
beets/util/__init__.py 87.50% 1 Missing and 1 partial ⚠️
beets/util/hidden.py 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6806      +/-   ##
==========================================
- Coverage   74.85%   74.84%   -0.01%     
==========================================
  Files         163      163              
  Lines       20970    20986      +16     
  Branches     3300     3304       +4     
==========================================
+ Hits        15697    15707      +10     
- Misses       4519     4522       +3     
- Partials      754      757       +3     
Files with missing lines Coverage Δ
beetsplug/fetchart.py 74.18% <100.00%> (ø)
beets/util/hidden.py 54.16% <83.33%> (+6.54%) ⬆️
beets/importer/tasks.py 90.87% <89.47%> (-0.29%) ⬇️
beets/util/__init__.py 80.35% <87.50%> (-0.33%) ⬇️
beets/util/extension.py 76.47% <70.00%> (-4.18%) ⬇️

... and 1 file 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 make path helper move from “bytes-only brain” toward “AnyStr brain” so code can walk filesystem with str or bytes and keep same type through.

Changes:

  • Make beets.util.hidden.is_hidden accept PathLike and decode/normalize into Path.
  • Change beets.util.sorted_walk typing/output to be generic over AnyStr (str/bytes) and adjust sorting to match path type.
  • Update importer albums_in_dir multi-disc detection so regex + ignore patterns work for both str and bytes paths.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
beets/util/hidden.py Widen hidden-path helper to accept broader path inputs and normalize via Path.
beets/util/init.py Make sorted_walk generic over AnyStr and preserve path type through traversal.
beets/importer/tasks.py Make albums_in_dir and multi-disc regex logic work for str and bytes paths.

Comment thread beets/util/__init__.py
Comment on lines +204 to +208
path: AnyStr,
ignore: Sequence[AnyStr] = (),
ignore_hidden: bool = False,
logger: Logger | None = None,
) -> Iterator[tuple[bytes, Sequence[bytes], Sequence[bytes]]]:
) -> Iterator[tuple[AnyStr, Sequence[AnyStr], Sequence[AnyStr]]]:
Comment thread beets/importer/tasks.py
) -> bool:

def is_subdir_of_any_in_list(path: AnyStr, dirs: list[AnyStr]) -> bool:
"""Returns True if path os a subdirectory of any directory in dirs
@snejus snejus force-pushed the make-bytes-utils-generic-over-anystr branch 5 times, most recently from 9edd8a2 to eb3e21e Compare June 30, 2026 18:01
@snejus snejus force-pushed the type-beets-util-test-helper branch from f2f5997 to 7716532 Compare June 30, 2026 20:59
@snejus snejus force-pushed the make-bytes-utils-generic-over-anystr branch from eb3e21e to 47376bf Compare June 30, 2026 20:59
@snejus snejus force-pushed the type-beets-util-test-helper branch from 7716532 to 9232a66 Compare July 1, 2026 07:10
@snejus snejus force-pushed the make-bytes-utils-generic-over-anystr branch from 47376bf to 010d0a7 Compare July 1, 2026 07:10
@snejus snejus force-pushed the type-beets-util-test-helper branch 2 times, most recently from c3bf07f to fc085e7 Compare July 5, 2026 11:59
@snejus snejus force-pushed the make-bytes-utils-generic-over-anystr branch from 010d0a7 to 374fff7 Compare July 5, 2026 12:02
Base automatically changed from type-beets-util-test-helper to master July 5, 2026 12:03
@snejus snejus force-pushed the make-bytes-utils-generic-over-anystr branch 4 times, most recently from 80bd9c8 to 62471bc Compare July 5, 2026 12:26
@snejus snejus force-pushed the make-bytes-utils-generic-over-anystr branch from 62471bc to db2e2fc Compare July 7, 2026 16:51
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.

Make path utilities generic over string path types

2 participants