typing: fix beets.dbcore.types

This commit is contained in:
Šarūnas Nejus
2026-07-06 15:19:21 +01:00
parent ea3d6af616
commit 1266256f5e
2 changed files with 7 additions and 4 deletions

View File

@@ -385,7 +385,10 @@ class BasePathType(Type[bytes, N]):
return value
def from_sql(self, sql_value: SQLiteType) -> bytes | N:
return pathutils.expand_path_from_db(self.normalize(sql_value))
value = self.normalize(sql_value)
if isinstance(value, bytes):
return pathutils.expand_path_from_db(value)
return value
def to_sql(self, value: pathutils.MaybeBytes) -> BLOB_TYPE | None:
value = pathutils.normalize_path_for_db(value)
@@ -451,7 +454,7 @@ class DurationType(Float):
def format(self, value: float) -> str:
if not beets.config["format_raw_length"].get(bool):
return human_seconds_short(value or 0.0)
return value
return str(value)
def parse(self, string: str) -> float | N:
try:

View File

@@ -56,8 +56,8 @@ def test_durationtype():
assert t.null == t.parse("not61.23")
# config format_raw_length
beets.config["format_raw_length"] = True
assert 61.23 == t.format(61.23)
assert 3601.23 == t.format(3601.23)
assert "61.23" == t.format(61.23)
assert "3601.23" == t.format(3601.23)
@pytest.mark.parametrize(