From 782a2ac6a775b96974fd0609b6b7a1bd1bdbe2be Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Tue, 28 Apr 2026 08:29:53 +0200 Subject: [PATCH] LCORE-2046: Pattern match in types --- src/utils/types.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/utils/types.py b/src/utils/types.py index 4280b89a3..018c264f6 100644 --- a/src/utils/types.py +++ b/src/utils/types.py @@ -65,17 +65,19 @@ def content_to_str(content: Any) -> str: ------- str: The normalized string representation of the content. """ - if content is None: - return "" - if isinstance(content, str): - return content - if isinstance(content, TextContentItem): - return content.text - if isinstance(content, ImageContentItem): - return "" - if isinstance(content, list): - return " ".join(content_to_str(item) for item in content) - return str(content) + match content: + case None: + return "" + case str(): + return content + case TextContentItem(): + return content.text + case ImageContentItem(): + return "" + case list(): + return " ".join(content_to_str(item) for item in content) + case _: + return str(content) class Singleton(type):