From a4f705bb6e1c18d4dfd9437c0ee16945b278f43d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Mon, 9 Feb 2026 22:28:45 +0000 Subject: [PATCH] Fix deprecation warning --- beets/autotag/hooks.py | 26 +++++++++----------------- test/autotag/test_hooks.py | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 test/autotag/test_hooks.py diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index ef9e8bb30..617d5051a 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -16,7 +16,6 @@ from __future__ import annotations -import warnings from copy import deepcopy from dataclasses import dataclass from functools import cached_property @@ -25,6 +24,7 @@ from typing import TYPE_CHECKING, Any, TypeVar from typing_extensions import Self from beets.util import cached_classproperty +from beets.util.deprecation import deprecate_for_maintainers if TYPE_CHECKING: from beets.library import Item @@ -81,25 +81,17 @@ class Info(AttrDict[Any]): media: str | None = None, **kwargs, ) -> None: - if genre: - warnings.warn( - "The 'genre' parameter is deprecated. Use 'genres' (list) instead.", - DeprecationWarning, - stacklevel=2, + if genre is not None: + deprecate_for_maintainers( + "The 'genre' parameter", "'genres' (list)", stacklevel=3 ) if not genres: - for separator in [", ", "; ", " / "]: - if separator in genre: - split_genres = [ - g.strip() - for g in genre.split(separator) - if g.strip() - ] - if len(split_genres) > 1: - genres = split_genres - break - if not genres: + try: + sep = next(s for s in [", ", "; ", " / "] if s in genre) + except StopIteration: genres = [genre] + else: + genres = list(map(str.strip, genre.split(sep))) self.album = album self.artist = artist diff --git a/test/autotag/test_hooks.py b/test/autotag/test_hooks.py new file mode 100644 index 000000000..e5de089e8 --- /dev/null +++ b/test/autotag/test_hooks.py @@ -0,0 +1,17 @@ +import pytest + +from beets.autotag.hooks import Info + + +@pytest.mark.parametrize( + "genre, expected_genres", + [ + ("Rock", ("Rock",)), + ("Rock; Alternative", ("Rock", "Alternative")), + ], +) +def test_genre_deprecation(genre, expected_genres): + with pytest.warns( + DeprecationWarning, match="The 'genre' parameter is deprecated" + ): + assert tuple(Info(genre=genre).genres) == expected_genres