Skip to content

Commit

Permalink
More closely match modern JSON Schema vocabulary in internal module n…
Browse files Browse the repository at this point in the history
…ames.

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.
  • Loading branch information
Julian committed Aug 9, 2023
1 parent 1b83f79 commit 9313230
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 207 deletions.
4 changes: 1 addition & 3 deletions docs/creating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ where in the instance or schema respectively the error occurred.
The Validator Protocol
----------------------

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

For full details, see `validator-protocol`.
9 changes: 2 additions & 7 deletions docs/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@ failed when validating a given instance, you may want to do so using

.. attribute:: errors

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

Consider the following example:

Expand Down Expand Up @@ -276,10 +274,7 @@ error objects.
from jsonschema.exceptions import ErrorTree
tree = ErrorTree(v.iter_errors(instance))

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 object's
`jsonschema.protocols.Validator.iter_errors` method.
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.

`ErrorTree`\s support a number of useful operations. The first one we
might want to perform is to check whether a given element in our instance
Expand Down
7 changes: 2 additions & 5 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ This library made the choice to leave it off by default, for two reasons:
implementations they were using to ensure they too were explicitly
enabled for :kw:`format` validation.

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

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.
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.

.. seealso::

Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions jsonschema/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from collections import namedtuple
from unittest import TestCase

from jsonschema import ValidationError, _validators
from jsonschema import ValidationError, _keywords
from jsonschema._types import TypeChecker
from jsonschema.exceptions import UndefinedTypeCheck, UnknownType
from jsonschema.validators import Draft202012Validator, extend
Expand Down Expand Up @@ -191,8 +191,8 @@ def coerced(validator, value, instance, schema):
return fn(validator, value, instance, schema)
return coerced

required = coerce_named_tuple(_validators.required)
properties = coerce_named_tuple(_validators.properties)
required = coerce_named_tuple(_keywords.required)
properties = coerce_named_tuple(_keywords.properties)

CustomValidator = extend(
Draft202012Validator,
Expand Down
Loading

0 comments on commit 9313230

Please sign in to comment.