Skip to content

Commit db81ea8

Browse files
committed
Move the documentation for validate into the validate docstring
This allows for a better experience when using the Python interactive interpreter.
1 parent dc9e996 commit db81ea8

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

docs/validate.rst

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,6 @@ The simplest way to validate an instance under a given schema is to use the
1414

1515
.. autofunction:: validate
1616

17-
Validate an instance under the given schema.
18-
19-
>>> validate([2, 3, 4], {"maxItems" : 2})
20-
Traceback (most recent call last):
21-
...
22-
ValidationError: [2, 3, 4] is too long
23-
24-
:func:`validate` will first verify that the provided schema is itself
25-
valid, since not doing so can lead to less obvious error messages and fail
26-
in less obvious or consistent ways. If you know you have a valid schema
27-
already or don't care, you might prefer using the
28-
:meth:`~IValidator.validate` method directly on a specific validator
29-
(e.g. :meth:`Draft4Validator.validate`).
30-
31-
32-
:argument instance: the instance to validate
33-
:argument schema: the schema to validate with
34-
:argument cls: an :class:`IValidator` class that will be used to validate
35-
the instance.
36-
37-
If the ``cls`` argument is not provided, two things will happen in
38-
accordance with the specification. First, if the schema has a
39-
:validator:`$schema` property containing a known meta-schema [#]_ then the
40-
proper validator will be used. The specification recommends that all
41-
schemas contain :validator:`$schema` properties for this reason. If no
42-
:validator:`$schema` property is found, the default validator class is
43-
:class:`Draft4Validator`.
44-
45-
Any other provided positional and keyword arguments will be passed on when
46-
instantiating the ``cls``.
47-
48-
:raises:
49-
:exc:`ValidationError` if the instance is invalid
50-
51-
:exc:`SchemaError` if the schema itself is invalid
52-
53-
.. rubric:: Footnotes
54-
.. [#] known by a validator registered with :func:`validates`
55-
56-
5717
The Validator Interface
5818
-----------------------
5919

jsonschema/validators.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,46 @@ def validator_for(schema, default=_unset):
462462

463463

464464
def validate(instance, schema, cls=None, *args, **kwargs):
465+
"""
466+
Validate an instance under the given schema.
467+
468+
>>> validate([2, 3, 4], {"maxItems" : 2})
469+
Traceback (most recent call last):
470+
...
471+
ValidationError: [2, 3, 4] is too long
472+
473+
:func:`validate` will first verify that the provided schema is itself
474+
valid, since not doing so can lead to less obvious error messages and fail
475+
in less obvious or consistent ways. If you know you have a valid schema
476+
already or don't care, you might prefer using the
477+
:meth:`~IValidator.validate` method directly on a specific validator
478+
(e.g. :meth:`Draft4Validator.validate`).
479+
480+
481+
:argument instance: the instance to validate
482+
:argument schema: the schema to validate with
483+
:argument cls: an :class:`IValidator` class that will be used to validate
484+
the instance.
485+
486+
If the ``cls`` argument is not provided, two things will happen in
487+
accordance with the specification. First, if the schema has a
488+
:validator:`$schema` property containing a known meta-schema [#]_ then the
489+
proper validator will be used. The specification recommends that all
490+
schemas contain :validator:`$schema` properties for this reason. If no
491+
:validator:`$schema` property is found, the default validator class is
492+
:class:`Draft4Validator`.
493+
494+
Any other provided positional and keyword arguments will be passed on when
495+
instantiating the ``cls``.
496+
497+
:raises:
498+
:exc:`ValidationError` if the instance is invalid
499+
500+
:exc:`SchemaError` if the schema itself is invalid
501+
502+
.. rubric:: Footnotes
503+
.. [#] known by a validator registered with :func:`validates`
504+
"""
465505
if cls is None:
466506
cls = validator_for(schema)
467507
cls.check_schema(schema)

0 commit comments

Comments
 (0)