Skip to content

Commit 7a42748

Browse files
committed
improve check_dict
Signed-off-by: Zen <[email protected]>
1 parent 5aac17a commit 7a42748

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "zenlib"
7-
version = "2.0.0"
7+
version = "2.0.1"
88
authors = [
99
{ name="Desultory", email="[email protected]" },
1010
]

src/zenlib/util/check_dict.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)