refactor(release): ParsedRelease.media_type & parse_path are strict enums

The fields were already typed as MediaTypeToken / ParsePath, but a
tolerant __post_init__ coerced raw strings into their enum form. With
MediaTypeToken(str, Enum) (and ParsePath idem), the coercion served no
purpose — callers that pass '.value' got back the enum anyway, and
callers that pass an unknown string got a ValidationError just like
they would now.

Strict mode: constructor rejects non-enum values directly. The two
in-tree builders (parse_release() and the parser pipeline) already
produce enum values; all .value sites have been removed. Drops the
unused _VALID_MEDIA_TYPES / _VALID_PARSE_PATHS lookup tables.
This commit is contained in:
2026-05-20 23:52:30 +02:00
parent c3767aacb6
commit 757e4045ee
4 changed files with 28 additions and 38 deletions
@@ -79,8 +79,8 @@ def _movie(year: int = 2020, **overrides) -> ParsedRelease:
codec="x264",
group="GROUP",
tech_string="1080p.BluRay.x264",
media_type=MediaTypeToken.MOVIE.value,
parse_path=ParsePath.DIRECT.value,
media_type=MediaTypeToken.MOVIE,
parse_path=ParsePath.DIRECT,
)
base.update(overrides)
return ParsedRelease(**base)
@@ -121,8 +121,8 @@ class TestComputeScore:
codec="x265",
group="KONTRAST",
tech_string="1080p.WEBRip.x265",
media_type=MediaTypeToken.TV_SHOW.value,
parse_path=ParsePath.DIRECT.value,
media_type=MediaTypeToken.TV_SHOW,
parse_path=ParsePath.DIRECT,
)
tokens = [
Token("Oz", 0, TokenRole.TITLE),
@@ -166,7 +166,7 @@ class TestComputeScore:
assert 0 <= score <= 100
def test_unknown_media_type_does_not_count(self) -> None:
parsed = _movie(media_type=MediaTypeToken.UNKNOWN.value)
parsed = _movie(media_type=MediaTypeToken.UNKNOWN)
score = compute_score(parsed, _all_annotated(), _KB)
# Loses the 20 of media_type vs baseline
assert score == 85 - 20
@@ -232,8 +232,8 @@ class TestCollectors:
codec=None,
group="UNKNOWN",
tech_string="",
media_type=MediaTypeToken.UNKNOWN.value,
parse_path=ParsePath.DIRECT.value,
media_type=MediaTypeToken.UNKNOWN,
parse_path=ParsePath.DIRECT,
)
assert set(collect_missing_critical(empty)) == {
"title",