@@ -53,15 +53,15 @@ def dispatch_msg(msg):
5353 else :
5454 dict_val = None
5555 else :
56- if unset :
56+ if unset and not contains :
5757 return dispatch_msg ("[%s] Key is set when it should be unset: %s." % (func .__name__ , key ))
5858 else :
5959 dict_val = validate_dict [key ]
6060 if not_empty and not dict_val :
6161 return dispatch_msg ("[%s] Key is not empty: %s." % (func .__name__ , key ))
6262 elif isinstance (key , dict ):
6363 if dict_val := walk_dict (validate_dict , key , fail_safe = not raise_exception ):
64- if unset :
64+ if unset and not contains :
6565 return dispatch_msg ("[%s] Key is set when it should be unset: %s." % (func .__name__ , dict_val ))
6666 if not_empty and not dict_val :
6767 return dispatch_msg ("[%s] Key is not empty: %s." % (func .__name__ , dict_val ))
@@ -70,7 +70,9 @@ def dispatch_msg(msg):
7070
7171 if check_val is not None :
7272 if contains :
73- if check_val not in dict_val :
73+ if unset and check_val in dict_val :
74+ return dispatch_msg ("[%s] Key: %s contains value: %s, but should not." % (func .__name__ , key , check_val ))
75+ if check_val not in dict_val and not unset :
7476 return dispatch_msg ("[%s] Dict does not contain key '%s': %s" % (func .__name__ , check_val , dict_val ))
7577 elif dict_val != check_val :
7678 return dispatch_msg ("[%s] Key: %s has value: %s, but expected: %s." % (func .__name__ , key , dict_val , check_val ))
0 commit comments