Skip to content

Commit

Permalink
Merge pull request #8 from njzjz/anykeys
Browse files Browse the repository at this point in the history
  • Loading branch information
y1xiaoc committed Apr 22, 2022
2 parents 2882cd2 + f0d92b7 commit 1b778b3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions dargs/dargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ def _check_value(self, value: Any, path=None):
def _check_strict(self, value: dict, path=None):
allowed_keys = self.flatten_sub(value, path).keys()
# curpath = [*path, self.name]
if not len(allowed_keys):
# no allowed keys defined, allow any keys
return
for name in value.keys():
if name not in allowed_keys:
raise ArgumentKeyError(path,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_name_type(self):
# check any keywords
ca = Argument("kwargs", dict)
anydict = {"this": 1, "that": 2, "any": 3}
ca.check({"kwargs": anydict})
ca.check({"kwargs": anydict}, strict=True)
ca.check_value(anydict)

def test_sub_fields(self):
Expand Down

0 comments on commit 1b778b3

Please sign in to comment.