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.
Description
Part 2 of the work fixing types in
beets.util.__init__
#5215.Mypy was not happy here because
_legalize_stage
function implementation concatenatespath
andextension
parameters, implying that their types need to match.You can see that initially
path
parameter was defined as astr
whileextension
wasbytes
.In reality, depending on the
fragment
parameter value,extension
was sometimes provided as astr
and sometimes asbytes
. The same parameter decided whetherpath
gets converted intobytes
within_legalize_stage
implementation. No surprise that mypy was confused here._legalize_stage
is only used withinItem.destination
method implementation which is wherefragment
is defined. I determined that thefragment
parameter controls the form of the output path:fragment=False
returned absolute path as bytes (default)fragment=True
returned path relative to the library directory as str.Given the above, the change
Renames
fragment
parameter torelative_to_libdir
for clarityMakes
Item.destination
to return the same type in both cases. I pickedbytes
since that's the type that majority of the code using this method expects.I converted the output path to
str
for the code that has been expecting a string there.Decouples
_legalize_stage
and_legalize_path
implementations from therelative_to_libdir
. The logic now usesstr
type only.