Skip to content

Commit 72d8d08

Browse files
committed
Simplify the implementations of the equal checks.
1 parent be4287c commit 72d8d08

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

jsonschema/_utils.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,12 @@ def _mapping_equal(one, two):
162162
"""
163163
Check if two mappings are equal using the semantics of `equal`.
164164
"""
165-
if len(one.keys()) != len(two.keys()):
165+
if len(one) != len(two):
166166
return False
167-
168-
for key in one:
169-
if key not in two:
170-
return False
171-
if not equal(one[key], two[key]):
172-
return False
173-
174-
return True
167+
return all(
168+
key in two and equal(value, two[key])
169+
for key, value in one.items()
170+
)
175171

176172

177173
def _sequence_equal(one, two):
@@ -180,12 +176,7 @@ def _sequence_equal(one, two):
180176
"""
181177
if len(one) != len(two):
182178
return False
183-
184-
for i in range(0, len(one)):
185-
if not equal(one[i], two[i]):
186-
return False
187-
188-
return True
179+
return all(equal(i, j) for i, j in zip(one, two))
189180

190181

191182
def equal(one, two):

0 commit comments

Comments
 (0)