Skip to content

Commit

Permalink
Fixed issue #1
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusfrdk committed Feb 12, 2025
1 parent 1c5e4e9 commit 4e55b01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
22 changes: 17 additions & 5 deletions tomlval/toml_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,17 @@ def compare_keys(self, dictionary: dict) -> list[str]:
provided_keys = set(
re.sub(nested_array_pattern, ".", k) for k in dictionary
)
required_keys = set(
k.replace("[]", "")
for k in self.keys()
if "*" not in k and "?" not in k
)

# Remove characters and map keys
required_keys = set()
nested_arrays = {}

for key in self.keys():
if "*" not in key and "?" not in key:
_key = key.replace("[]", "")
if "[]" in key:
nested_arrays[_key] = key
required_keys.add(_key)

# Wildcard keys
for key in self.keys():
Expand All @@ -225,6 +231,12 @@ def compare_keys(self, dictionary: dict) -> list[str]:
):
required_keys.add(pattern)

# Re-substitute keys
for k, v in nested_arrays.items():
if k in required_keys:
required_keys.remove(k)
required_keys.add(v)

return list(required_keys - provided_keys)


Expand Down
7 changes: 6 additions & 1 deletion tomlval/toml_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ def __init__(
_otm_params = set(inspect.signature(on_type_mismatch).parameters)
if not {"key", "expected", "got"}.issubset(_otm_params):
raise TypeError(
"on_type_mismatch must accept parameters 'key', 'expected' and 'got'."
" ".join(
[
"on_type_mismatch must accept",
"parameters 'key', 'expected' and 'got'.",
]
)
)

self._schema = schema or TOMLSchema({})
Expand Down

0 comments on commit 4e55b01

Please sign in to comment.