From 8b00e0357bfc7fc1e512c55e99ac6fddcaaa1187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 26 Mar 2024 13:12:05 +0100 Subject: [PATCH] Change: Improve to_comma_list function signature Allow to pass any object that supports the __str__ protocol method. --- gvm/utils.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/gvm/utils.py b/gvm/utils.py index 293af5c56..1339542ce 100644 --- a/gvm/utils.py +++ b/gvm/utils.py @@ -10,7 +10,16 @@ import re import warnings from functools import wraps -from typing import Any, Callable, List, Optional, Type, Union +from typing import ( + Any, + Callable, + Iterable, + List, + Optional, + Protocol, + Type, + Union, +) from gvm.xml import XmlCommand, XmlError, parse_xml @@ -146,8 +155,12 @@ def to_base64(value: str) -> str: return base64.b64encode(value.encode("utf-8")).decode(encoding="utf-8") -def to_comma_list(value: List) -> str: - return ",".join(value) +class SupportsStr(Protocol): + def __str__(self) -> str: ... + + +def to_comma_list(value: Iterable[SupportsStr]) -> str: + return ",".join([str(value) for value in value]) @deprecated(since="24.3.0", reason="Please use XmlCommand.add_filter instead.")