Skip to content

Commit 94dea8b

Browse files
committed
Fix references to IValidator; add protocol tests
Several remaining cases referred to `IValidator` which is now just `Validtator`. Fix these. Add a test which ensures that all valdiators pass `isinstance(x, Validator)` using the runtime-checkable protocol.
1 parent 642a09f commit 94dea8b

File tree

7 files changed

+32
-10
lines changed

7 files changed

+32
-10
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Features
7474
and
7575
`Draft 3 <https://python-jsonschema.readthedocs.io/en/latest/validate/#jsonschema.Draft3Validator>`_
7676

77-
* `Lazy validation <https://python-jsonschema.readthedocs.io/en/latest/validate/#jsonschema.IValidator.iter_errors>`_
77+
* `Lazy validation <https://python-jsonschema.readthedocs.io/en/latest/validate/#jsonschema.Validator.iter_errors>`_
7878
that can iteratively report *all* validation errors.
7979

8080
* `Programmatic querying <https://python-jsonschema.readthedocs.io/en/latest/errors/>`_

docs/spelling-wordlist.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# this appears to be misinterpreting Napoleon types as prose, sigh...
2-
IValidator
2+
Validator
33
TypeChecker
44
UnknownType
55
ValidationError

docs/validate.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ more information see `creating-validators`.
3838
Type Checking
3939
-------------
4040

41-
To handle JSON Schema's :validator:`type` property, a `IValidator` uses
41+
To handle JSON Schema's :validator:`type` property, a `Validator` uses
4242
an associated `TypeChecker`. The type checker provides an immutable
4343
mapping between names of types and functions that can test if an instance is
4444
of that type. The defaults are suitable for most users - each of the
@@ -82,7 +82,7 @@ given how common validating these types are.
8282
If you *do* want the generality, or just want to add a few specific additional
8383
types as being acceptable for a validator object, then you should update an
8484
existing `TypeChecker` or create a new one. You may then create a new
85-
`IValidator` via `jsonschema.validators.extend`.
85+
`Validator` via `jsonschema.validators.extend`.
8686

8787
.. code-block:: python
8888
@@ -110,7 +110,7 @@ Versioned Validators
110110

111111
`jsonschema` ships with validator classes for various versions of
112112
the JSON Schema specification. For details on the methods and attributes
113-
that each validator class provides see the `IValidator` interface,
113+
that each validator class provides see the `Validator` interface,
114114
which each included validator class implements.
115115

116116
.. autoclass:: Draft202012Validator
@@ -155,7 +155,7 @@ JSON Schema defines the :validator:`format` property which can be used to check
155155
if primitive types (``string``\s, ``number``\s, ``boolean``\s) conform to
156156
well-defined formats. By default, no validation is enforced, but optionally,
157157
validation can be enabled by hooking in a format-checking object into an
158-
`IValidator`.
158+
`Validator`.
159159

160160
.. doctest::
161161

jsonschema/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
SchemaError,
2727
ValidationError,
2828
)
29+
from jsonschema.protocols import Validator
2930
from jsonschema.validators import (
3031
Draft3Validator,
3132
Draft4Validator,

jsonschema/_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class TypeChecker(object):
4949
"""
5050
A ``type`` property checker.
5151
52-
A `TypeChecker` performs type checking for an `IValidator`. Type
52+
A `TypeChecker` performs type checking for a `Validator`. Type
5353
checks to perform are updated using `TypeChecker.redefine` or
5454
`TypeChecker.redefine_many` and removed via `TypeChecker.remove`.
5555
Each of these return a new `TypeChecker` object.

jsonschema/tests/test_validators.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313

1414
import attr
1515

16-
from jsonschema import FormatChecker, TypeChecker, exceptions, validators
16+
from jsonschema import (
17+
FormatChecker,
18+
TypeChecker,
19+
exceptions,
20+
protocols,
21+
validators,
22+
)
1723
from jsonschema.tests._helpers import bug
1824

1925

@@ -2128,6 +2134,21 @@ def test_helpful_error_message_on_failed_pop_scope(self):
21282134
self.assertIn("Failed to pop the scope", str(exc.exception))
21292135

21302136

2137+
class TestValidatorProtocol(TestCase):
2138+
def test_each_validator_is_instance_of_protocol(self):
2139+
schema = {}
2140+
for validator_cls in [
2141+
validators.Draft3Validator,
2142+
validators.Draft4Validator,
2143+
validators.Draft6Validator,
2144+
validators.Draft7Validator,
2145+
validators.Draft201909Validator,
2146+
validators.Draft202012Validator,
2147+
]:
2148+
validator = validator_cls(schema)
2149+
assert isinstance(validator, protocols.Validator)
2150+
2151+
21312152
def sorted_errors(errors):
21322153
def key(error):
21332154
return (

jsonschema/validators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ def validate(instance, schema, cls=None, *args, **kwargs):
917917
918918
If you know you have a valid schema already, especially if you
919919
intend to validate multiple instances with the same schema, you
920-
likely would prefer using the `IValidator.validate` method directly
920+
likely would prefer using the `Validator.validate` method directly
921921
on a specific validator (e.g. ``Draft7Validator.validate``).
922922
923923
@@ -931,7 +931,7 @@ def validate(instance, schema, cls=None, *args, **kwargs):
931931
932932
The schema to validate with
933933
934-
cls (IValidator):
934+
cls (Validator):
935935
936936
The class that will be used to validate the instance.
937937

0 commit comments

Comments
 (0)