summaryrefslogtreecommitdiff
path: root/jsonschema/_legacy_validators.py
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2021-08-25 18:34:29 +0100
committerJulian Berman <Julian@GrayVines.com>2021-08-25 18:34:29 +0100
commit996437f0693adf66ac6d24df7770057fc0fd9b15 (patch)
treed07f9d80d67799ffa85b62f7f0e07398ef94417e /jsonschema/_legacy_validators.py
parent452169710f20a38372bdd686f79680df1215d188 (diff)
downloadjsonschema-996437f0693adf66ac6d24df7770057fc0fd9b15.tar.gz
Add Validator.evolve, deprecating passing _schema to methods.
A Validator should be thought of as encapsulating validation with a single fixed schema. Previously, iter_errors and is_valid allowed passing a second argument, which was a different schema to use for one method call. This was mostly for convenience, since the second argument is often used during sub-validation whilst say, recursing. The correct way to do so now is to say: validator.evolve(schema=new_schema).iter_errors(...) validator.evolve(schema=new_schema).is_valid(...) instead, which is essentially equally convenient. Closes: #522
Diffstat (limited to 'jsonschema/_legacy_validators.py')
-rw-r--r--jsonschema/_legacy_validators.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/jsonschema/_legacy_validators.py b/jsonschema/_legacy_validators.py
index c0bab32..c8eff2c 100644
--- a/jsonschema/_legacy_validators.py
+++ b/jsonschema/_legacy_validators.py
@@ -72,7 +72,7 @@ def dependencies_draft4_draft6_draft7(
def disallow_draft3(validator, disallow, instance, schema):
for disallowed in _utils.ensure_list(disallow):
- if validator.is_valid(instance, {"type": [disallowed]}):
+ if validator.evolve(schema={"type": [disallowed]}).is_valid(instance):
message = f"{disallowed!r} is disallowed for {instance!r}"
yield ValidationError(message)
@@ -200,7 +200,10 @@ def contains_draft6_draft7(validator, contains, instance, schema):
if not validator.is_type(instance, "array"):
return
- if not any(validator.is_valid(element, contains) for element in instance):
+ if not any(
+ validator.evolve(schema=contains).is_valid(element)
+ for element in instance
+ ):
yield ValidationError(
f"None of {instance!r} are valid under the given schema",
)