Skip to content

Commit

Permalink
restrict validation to more_values
Browse files Browse the repository at this point in the history
  • Loading branch information
sbittrich committed Dec 23, 2024
1 parent 8292237 commit a9b471b
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions molviewspec/molviewspec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,30 @@ def make_params(params_type: Type[TParams], values=None, /, **more_values: objec
if values is None:
values = {}
result = {}
consumed = set()
consumed_more_values = set()

# propagate custom properties
if values:
custom_values = values.get("custom")
if custom_values is not None:
result["custom"] = custom_values
consumed.add("custom")
ref = values.get("ref")
if ref is not None:
result["ref"] = ref
consumed.add("ref")

for field in params_type.__fields__.values():
# must use alias here to properly resolve goodies like `schema_`
key = field.alias

if more_values.get(key) is not None:
result[key] = more_values[key]
consumed.add(key)
consumed_more_values.add(key)
elif values.get(key) is not None:
result[key] = values[key]
consumed.add(key)
elif field.default is not None: # currently not used
result[key] = field.default
consumed.add(key)

non_model_keys = set(more_values.keys()) - consumed
non_model_keys = set(more_values.keys()) - consumed_more_values
if non_model_keys:
raise ValueError(f"Encountered unknown attribute on {params_type}: {non_model_keys}")

Expand Down

0 comments on commit a9b471b

Please sign in to comment.