feat(validation): check the contents of a raw option that holds a dict or list

This commit is contained in:
2026-10-05 18:12:41 +02:00
parent 75ea3f10e2
commit d0916e5d2b
3 changed files with 27 additions and 4 deletions
+4 -2
View File
@@ -79,9 +79,11 @@ class _Validator:
if "choices" in spec and value not in spec["choices"]:
shown = "" if spec.get("no_log") else f", got {value!r}"
self.errors.append(f"{path}: must be one of {', '.join(map(str, spec['choices']))}{shown}")
if kind == "dict" and "options" in spec:
# Keyed on the value, not the declared type, so a `raw` option ("false, or a dict of...") is
# still checked whenever it holds a dict or a list.
if "options" in spec and isinstance(value, Mapping):
self.check_options(spec["options"], value, path)
elif kind == "list" and "elements" in spec:
elif "elements" in spec and isinstance(value, list):
element = {"type": spec["elements"]}
if "options" in spec:
element["options"] = spec["options"]