Skip to content

Commit 641e9b8

Browse files
committed
Slightly nicer error message for not.
1 parent 0b7315c commit 641e9b8

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

jsonschema/_validators.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,8 @@ def oneOf(validator, oneOf, instance, schema):
397397

398398
def not_(validator, not_schema, instance, schema):
399399
if validator.is_valid(instance, not_schema):
400-
yield ValidationError(
401-
f"{not_schema!r} is not allowed for {instance!r}",
402-
)
400+
message = f"{instance!r} should not be valid under {not_schema!r}"
401+
yield ValidationError(message)
403402

404403

405404
def if_(validator, if_schema, instance, schema):

jsonschema/tests/test_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ def test_propertyNames(self):
10221022
self.assertEqual(error.validator, "not")
10231023
self.assertEqual(
10241024
error.message,
1025-
"{'const': 'foo'} is not allowed for 'foo'",
1025+
"'foo' should not be valid under {'const': 'foo'}",
10261026
)
10271027
self.assertEqual(error.path, deque([]))
10281028
self.assertEqual(error.json_path, "$")

0 commit comments

Comments
 (0)