Skip to content

Commit 642a09f

Browse files
sirosenJulian
andcommitted
Apply suggestions from code review
Primarily, rewrite `IValidator` to `Validator` Co-authored-by: Julian Berman <[email protected]>
1 parent 5a99f6d commit 642a09f

File tree

6 files changed

+15
-14
lines changed

6 files changed

+15
-14
lines changed

docs/creating.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ where in the instance or schema respectively the error occurred.
2727
The Validator Protocol
2828
----------------------
2929

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

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

docs/errors.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ error objects.
275275
As you can see, `jsonschema.exceptions.ErrorTree` takes an
276276
iterable of `ValidationError`\s when constructing a tree so
277277
you can directly pass it the return value of a validator object's
278-
`jsonschema.protocols.IValidator.iter_errors` method.
278+
`jsonschema.protocols.Validator.iter_errors` method.
279279

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

docs/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ but fail the second!
9090

9191
Still, filling in defaults is a thing that is useful. `jsonschema`
9292
allows you to `define your own validator classes and callables
93-
<creating>`, so you can easily create an `jsonschema.protocols.IValidator`
93+
<creating>`, so you can easily create an `jsonschema.protocols.Validator`
9494
that does do default setting. Here's some code to get you started. (In
9595
this code, we add the default properties to each object *before* the
9696
properties are validated, so the default values themselves will need to

docs/validate.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ The simplest way to validate an instance under a given schema is to use the
2121
2222
.. _validator-protocol:
2323

24-
The Validator Interface
24+
The Validator Protocol
2525
-----------------------
2626

2727
`jsonschema` defines a protocol that all validator
2828
classes should adhere to.
2929

30-
.. autoclass:: jsonschema.protocols.IValidator
30+
.. autoclass:: jsonschema.protocols.Validator
3131
:members:
3232

3333
All of the `versioned validators <versioned-validators>` that are included with
34-
`jsonschema` adhere to the interface, and implementers of validator classes
34+
`jsonschema` adhere to the protocol, and implementers of validator classes
3535
that extend or complement the ones included should adhere to it as well. For
3636
more information see `creating-validators`.
3737

jsonschema/protocols.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
except ImportError:
1313
from typing_extensions import Protocol, runtime_checkable
1414

15-
from ._format import FormatChecker
15+
from jsonschema._format import FormatChecker
16+
1617
from ._types import TypeChecker
1718
from .exceptions import ValidationError
1819
from .validators import RefResolver
@@ -31,14 +32,14 @@
3132

3233

3334
@runtime_checkable
34-
class IValidator(Protocol):
35+
class Validator(Protocol):
3536
"""
3637
The protocol to which all validator classes should adhere.
3738
3839
:argument dict schema: the schema that the validator object
3940
will validate with. It is assumed to be valid, and providing
4041
an invalid schema can lead to undefined behavior. See
41-
`IValidator.check_schema` to validate a schema first.
42+
`Validator.check_schema` to validate a schema first.
4243
:argument resolver: an instance of `jsonschema.RefResolver` that will be
4344
used to resolve :validator:`$ref` properties (JSON references). If
4445
unprovided, one will be created.
@@ -138,7 +139,7 @@ def validate(self, instance: dict) -> None:
138139
ValidationError: [2, 3, 4] is too long
139140
"""
140141

141-
def evolve(self, **kwargs) -> "IValidator":
142+
def evolve(self, **kwargs) -> "Validator":
142143
"""
143144
Create a new validator like this one, but with given changes.
144145

jsonschema/validators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def create(
155155
156156
Returns:
157157
158-
a new `jsonschema.protocols.IValidator` class
158+
a new `jsonschema.protocols.Validator` class
159159
"""
160160

161161
@attr.s
@@ -284,7 +284,7 @@ def extend(validator, validators=(), version=None, type_checker=None):
284284
285285
Arguments:
286286
287-
validator (jsonschema.protocols.IValidator):
287+
validator (jsonschema.protocols.Validator):
288288
289289
an existing validator class
290290
@@ -314,11 +314,11 @@ def extend(validator, validators=(), version=None, type_checker=None):
314314
a type checker, used when applying the :validator:`type` validator.
315315
316316
If unprovided, the type checker of the extended
317-
`jsonschema.protocols.IValidator` will be carried along.
317+
`jsonschema.protocols.Validator` will be carried along.
318318
319319
Returns:
320320
321-
a new `jsonschema.protocols.IValidator` class extending the one
321+
a new `jsonschema.protocols.Validator` class extending the one
322322
provided
323323
324324
.. note:: Meta Schemas

0 commit comments

Comments
 (0)