mirror of
https://github.com/beetbox/beets.git
synced 2026-02-27 01:32:30 +01:00
Fix deprecation warning
This commit is contained in:
parent
a815d7ea22
commit
a4f705bb6e
2 changed files with 26 additions and 17 deletions
|
|
@ -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
|
||||
|
|
|
|||
17
test/autotag/test_hooks.py
Normal file
17
test/autotag/test_hooks.py
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue