From edfe00516f24d77b625a2e5b1c6557bc710438dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Mon, 23 Feb 2026 00:33:24 +0000 Subject: [PATCH] Handle DelimitedString fields as native lists in edit plugin Treat DelimitedString as a safe YAML-editable type in the edit plugin, allowing multi-valued fields to be edited as native lists. --- beets/dbcore/types.py | 6 ++++-- beetsplug/edit.py | 7 ++++++- docs/changelog.rst | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/beets/dbcore/types.py b/beets/dbcore/types.py index 3f94afd05..8907584a4 100644 --- a/beets/dbcore/types.py +++ b/beets/dbcore/types.py @@ -66,6 +66,8 @@ class Type(ABC, Generic[T, N]): """The `Query` subclass to be used when querying the field. """ + # For sequence-like types, keep ``model_type`` unsubscripted as it's used + # for ``isinstance`` checks. Use ``list`` instead of ``list[str]`` model_type: type[T] """The Python type that is used to represent the value in the model. @@ -287,7 +289,7 @@ class String(BaseString[str, Any]): model_type = str -class DelimitedString(BaseString[list[str], list[str]]): +class DelimitedString(BaseString[list, list]): # type: ignore[type-arg] r"""A list of Unicode strings, represented in-database by a single string containing delimiter-separated values. @@ -297,7 +299,7 @@ class DelimitedString(BaseString[list[str], list[str]]): as it contains a backslash character. """ - model_type = list[str] + model_type = list fmt_delimiter = "; " def __init__(self, db_delimiter: str): diff --git a/beetsplug/edit.py b/beetsplug/edit.py index 46e756122..0f358c9a1 100644 --- a/beetsplug/edit.py +++ b/beetsplug/edit.py @@ -30,7 +30,12 @@ from beets.util import PromptChoice # These "safe" types can avoid the format/parse cycle that most fields go # through: they are safe to edit with native YAML types. -SAFE_TYPES = (types.BaseFloat, types.BaseInteger, types.Boolean) +SAFE_TYPES = ( + types.BaseFloat, + types.BaseInteger, + types.Boolean, + types.DelimitedString, +) class ParseError(Exception): diff --git a/docs/changelog.rst b/docs/changelog.rst index 58ad3d58f..9f73a5725 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -29,6 +29,9 @@ Other changes Previously, ``\␀`` was used as a separator. This applies to fields such as ``artists``, ``albumtypes`` etc. - Improve highlighting of multi-valued fields changes. +- :doc:`plugins/edit`: Editing multi-valued fields now behaves more naturally, + with list values handled directly to make metadata edits smoother and more + predictable. 2.6.2 (February 22, 2026) -------------------------