Skip to content

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

Open
snejus wants to merge 1 commit into
type-beets-util-test-helperfrom
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 1 commit into
type-beets-util-test-helperfrom
make-bytes-utils-generic-over-anystr

Conversation

@snejus

@snejus snejus commented Jun 30, 2026

Copy link
Copy Markdown
Member
  • 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

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
2589 1 2588 64
View the top 1 failed test(s) by shortest run time
test/test_importer.py::TestMpeglayerWavImport::test_remux_mpeglayer3_wav
Stack Traces | 0.015s run time
self = <test.test_importer.TestMpeglayerWavImport object at 0x7f56dab25930>

    #x1B[0m#x1B[94mdef#x1B[39;49;00m#x1B[90m #x1B[39;49;00m#x1B[92mtest_remux_mpeglayer3_wav#x1B[39;49;00m(#x1B[96mself#x1B[39;49;00m):#x1B[90m#x1B[39;49;00m
        src = os.path.join(_common.RSRC, #x1B[33mb#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33mmpeglayer3.wav#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m)#x1B[90m#x1B[39;49;00m
        dest = os.path.join(#x1B[96mself#x1B[39;49;00m.temp_dir, #x1B[33mb#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[33mmpeglayer3.wav#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m)#x1B[90m#x1B[39;49;00m
        shutil.copy(syspath(src), syspath(dest))#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        mp3_path = remux_mpeglayer3_wav(dest)#x1B[90m#x1B[39;49;00m
    #x1B[90m#x1B[39;49;00m
        #x1B[94massert#x1B[39;49;00m mp3_path #x1B[95mis#x1B[39;49;00m #x1B[95mnot#x1B[39;49;00m #x1B[94mNone#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
>       #x1B[94massert#x1B[39;49;00m mp3_path.suffix == #x1B[33m"#x1B[39;49;00m#x1B[33m.mp3#x1B[39;49;00m#x1B[33m"#x1B[39;49;00m#x1B[90m#x1B[39;49;00m
#x1B[1m#x1B[31mE       AttributeError: 'bytes' object has no attribute 'suffix'#x1B[0m

#x1B[1m#x1B[31mtest/test_importer.py#x1B[0m:1904: AttributeError

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

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