Skip to content

Commit 9313230

Browse files
committed
More closely match modern JSON Schema vocabulary in internal module names.
These are private, so it's easy to rename them to use preferred modern terminology, namely that individual keywords are called 'keywords' rather than 'validators'. This leaves the latter ('validator') to have one fewer overloaded meaning in this library, leaving it primarily referring to class objects such as DraftNValidator objects, however there are still at least 2 public places where we conflate terminology: * In the VALIDATORS attribute on validator classes, where this attribute is a mapping from str to callable but really the callables are callables for each *keyword* * ValidationError.validator, which is really the *keyword* which failed validation These are of course public API and need deprecating, which hasn't been done thus far mostly to not create API churn simply to rename. In the future however, it's likely that broader deprecations will help us deprecate these. Specifically when we implement fuller support for vocabularies and/or deprecate jsonschema.validators.create in favor of newer objects, we may get a chance to replace VALIDATORS, and when we implement more robust exception types (e.g. to address #119) we likely will deprecate .validator.
1 parent 1b83f79 commit 9313230

File tree

7 files changed

+197
-207
lines changed

7 files changed

+197
-207
lines changed

docs/creating.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ where in the instance or schema respectively the error occurred.
3131
The Validator Protocol
3232
----------------------
3333

34-
``jsonschema`` defines a `protocol <typing.Protocol>`,
35-
`jsonschema.protocols.Validator` which can be used in type annotations to
36-
describe the type of a validator object.
34+
``jsonschema`` defines a `protocol <typing.Protocol>`, `jsonschema.protocols.Validator` which can be used in type annotations to describe the type of a validator.
3735

3836
For full details, see `validator-protocol`.

docs/errors.rst

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,7 @@ failed when validating a given instance, you may want to do so using
238238

239239
.. attribute:: errors
240240

241-
The mapping of validator keywords to the error objects (usually
242-
`jsonschema.exceptions.ValidationError`\s) at this level
243-
of the tree.
241+
The mapping of validation keywords to the error objects (usually `jsonschema.exceptions.ValidationError`\s) at this level of the tree.
244242

245243
Consider the following example:
246244

@@ -276,10 +274,7 @@ error objects.
276274
from jsonschema.exceptions import ErrorTree
277275
tree = ErrorTree(v.iter_errors(instance))
278276

279-
As you can see, `jsonschema.exceptions.ErrorTree` takes an
280-
iterable of `ValidationError`\s when constructing a tree so
281-
you can directly pass it the return value of a validator object's
282-
`jsonschema.protocols.Validator.iter_errors` method.
277+
As you can see, `jsonschema.exceptions.ErrorTree` takes an iterable of `ValidationError`\s when constructing a tree so you can directly pass it the return value of a validator's `jsonschema.protocols.Validator.iter_errors` method.
283278

284279
`ErrorTree`\s support a number of useful operations. The first one we
285280
might want to perform is to check whether a given element in our instance

docs/faq.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,9 @@ This library made the choice to leave it off by default, for two reasons:
5050
implementations they were using to ensure they too were explicitly
5151
enabled for :kw:`format` validation.
5252

53-
As of ``draft2019-09`` however, the opt-out by default behavior
54-
mentioned here is now *required* for all validators.
53+
As of ``draft2019-09`` however, the opt-out by default behavior mentioned here is now *required* for all implementations of JSON Schema.
5554

56-
Difficult as this may sound for new users, at this point it at least
57-
means they should expect the same behavior that has always been
58-
implemented here, across any other implementation they encounter.
55+
Difficult as this may sound for new users, at this point it at least means they should expect the same behavior that has always been implemented here, across any other implementation they encounter.
5956

6057
.. seealso::
6158

File renamed without changes.
File renamed without changes.

jsonschema/tests/test_types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from collections import namedtuple
99
from unittest import TestCase
1010

11-
from jsonschema import ValidationError, _validators
11+
from jsonschema import ValidationError, _keywords
1212
from jsonschema._types import TypeChecker
1313
from jsonschema.exceptions import UndefinedTypeCheck, UnknownType
1414
from jsonschema.validators import Draft202012Validator, extend
@@ -191,8 +191,8 @@ def coerced(validator, value, instance, schema):
191191
return fn(validator, value, instance, schema)
192192
return coerced
193193

194-
required = coerce_named_tuple(_validators.required)
195-
properties = coerce_named_tuple(_validators.properties)
194+
required = coerce_named_tuple(_keywords.required)
195+
properties = coerce_named_tuple(_keywords.properties)
196196

197197
CustomValidator = extend(
198198
Draft202012Validator,

0 commit comments

Comments
 (0)