Skip to content

Commit 8dc2889

Browse files
committed
Add helper function
1 parent c9d1a65 commit 8dc2889

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

jsonschema/_utils.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema):
270270
return []
271271
evaluated_keys = []
272272

273+
def is_valid(errs_it):
274+
"""Whether there are no errors in the given iterator."""
275+
return next(errs_it, None) is None
276+
273277
ref = schema.get("$ref")
274278
if ref is not None:
275279
resolved = validator._resolver.lookup(ref)
@@ -326,13 +330,12 @@ def find_evaluated_property_keys_by_schema(validator, instance, schema):
326330
)
327331

328332
for keyword in ["allOf", "oneOf", "anyOf"]:
329-
if keyword in schema:
330-
for subschema in schema[keyword]:
331-
errs = next(validator.descend(instance, subschema), None)
332-
if errs is None:
333-
evaluated_keys += find_evaluated_property_keys_by_schema(
334-
validator, instance, subschema,
335-
)
333+
for subschema in schema.get(keyword, []):
334+
if not is_valid(validator.descend(instance, subschema)):
335+
continue
336+
evaluated_keys += find_evaluated_property_keys_by_schema(
337+
validator, instance, subschema,
338+
)
336339

337340
if "if" in schema:
338341
if validator.evolve(schema=schema["if"]).is_valid(instance):

0 commit comments

Comments
 (0)