tests/f2: allow string lists as config values
not all values are sets. the search path for example is definitely ordered. Change-Id: Ice94fe324319731ae3a83c757768c48576ba8b36
This commit is contained in:
@@ -62,12 +62,12 @@ class NixSettings:
|
||||
|
||||
def serialise(value: Any) -> str:
|
||||
# TODO(Commentator2.0): why exactly are ints supported?
|
||||
if is_value_of_type(value, set[str | int]):
|
||||
if is_value_of_type(value, set[str | int] | list[str | int]):
|
||||
return " ".join(serialise(e) for e in value)
|
||||
if is_value_of_type(value, str | int):
|
||||
return str(value)
|
||||
|
||||
msg = f"Value is unsupported in nix config: {value!r}, must bei either `str|int` or `set[str|int]`"
|
||||
msg = f"Value is unsupported in nix config: {value!r}, must bei either `str|int` or `set[str|int]` or `list[str|int]`"
|
||||
raise ValueError(msg)
|
||||
|
||||
def field_may(name: str, value: Any, serializer: Callable[[Any], str] = serialise):
|
||||
|
||||
@@ -11,6 +11,7 @@ def test_list_type_valid():
|
||||
|
||||
def test_list_type_valid_multi_type():
|
||||
assert is_value_of_type([1, "a", 2], list[int | str])
|
||||
assert is_value_of_type([1, "a", 2], set[str | int] | list[int | str])
|
||||
|
||||
|
||||
def test_list_type_invalid_single_fail():
|
||||
|
||||
@@ -120,8 +120,10 @@ def is_value_of_type(value: Any, expected_type: type[Any] | UnionType) -> bool:
|
||||
if expected_type is Any:
|
||||
return True
|
||||
match origin:
|
||||
case None | types.UnionType:
|
||||
case None:
|
||||
return isinstance(value, expected_type)
|
||||
case types.UnionType:
|
||||
return any(is_value_of_type(value, t) for t in get_args(expected_type))
|
||||
case typing.Literal:
|
||||
return value in get_args(expected_type)
|
||||
case builtins.type:
|
||||
|
||||
Reference in New Issue
Block a user