Skip to content

Commit cca2283

Browse files
committed
added 'contains' flag to check if the value is in the dict
Signed-off-by: Zen <[email protected]>
1 parent ad9f12a commit cca2283

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/zenlib/util/check_dict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def walk_dict(d, walk_key, raise_exception=True):
1717
return d[key][subkey]
1818

1919

20-
def check_dict(key, validate_dict=None, value=None, value_arg=None, unset=False, raise_exception=False, log_level=10, return_val=False, return_arg=None, message=None):
20+
def check_dict(key, validate_dict=None, value=None, value_arg=None, contains=False, unset=False, raise_exception=False, log_level=10, return_val=False, return_arg=None, message=None):
2121
"""
2222
Adds a check for a dict key to a function.
2323
If the dict is nto passed, uses the first argument of the function (often self).
@@ -71,7 +71,7 @@ def dispatch_msg(msg):
7171
raise ValueError("Unable to find key: %s." % key)
7272

7373
if check_val is not None:
74-
if isinstance(dict_val, dict):
74+
if contains:
7575
if check_val not in dict_val:
7676
return dispatch_msg("[%s] Dict does not contain key '%s': %s" % (func.__name__, check_val, dict_val))
7777
elif dict_val != check_val:

0 commit comments

Comments
 (0)