Skip to content

Commit 28a8666

Browse files
committed
Convert more docs in protocols to napoleon.
Also rely more on sphinx's type annotation support, which seems to detect the argument types without duplicating.
1 parent aa156de commit 28a8666

File tree

1 file changed

+56
-26
lines changed

1 file changed

+56
-26
lines changed

jsonschema/protocols.py

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,30 @@ class Validator(Protocol):
5050
"""
5151
The protocol to which all validator classes should adhere.
5252
53-
:argument schema: the schema that the validator object
54-
will validate with. It is assumed to be valid, and providing
55-
an invalid schema can lead to undefined behavior. See
56-
`Validator.check_schema` to validate a schema first.
57-
:argument resolver: an instance of `jsonschema.RefResolver` that will be
58-
used to resolve :kw:`$ref` properties (JSON references). If
59-
unprovided, one will be created.
60-
:argument format_checker: an instance of `jsonschema.FormatChecker`
61-
whose `jsonschema.FormatChecker.conforms` method will be called to
62-
check and see if instances conform to each :kw:`format`
63-
property present in the schema. If unprovided, no validation
64-
will be done for :kw:`format`. Certain formats require
65-
additional packages to be installed (ipv5, uri, color, date-time).
66-
The required packages can be found at the bottom of this page.
53+
Arguments:
54+
55+
schema:
56+
57+
The schema that the validator object will validate with.
58+
It is assumed to be valid, and providing
59+
an invalid schema can lead to undefined behavior. See
60+
`Validator.check_schema` to validate a schema first.
61+
62+
resolver:
63+
64+
a resolver that will be used to resolve :kw:`$ref`
65+
properties (JSON references). If unprovided, one will be created.
66+
67+
format_checker:
68+
69+
if provided, a checker which will be used to assert about
70+
:kw:`format` properties present in the schema. If unprovided,
71+
*no* format validation is done, and the presence of format
72+
within schemas is strictly informational. Certain formats
73+
require additional packages to be installed in order to assert
74+
against instances. Ensure you've installed `jsonschema` with
75+
its `extra (optional) dependencies <index:extras>` when
76+
invoking ``pip``.
6777
"""
6878

6979
#: An object representing the validator's meta schema (the schema that
@@ -99,25 +109,45 @@ def check_schema(cls, schema: dict) -> None:
99109
"""
100110
Validate the given schema against the validator's `META_SCHEMA`.
101111
102-
:raises: `jsonschema.exceptions.SchemaError` if the schema
103-
is invalid
112+
Raises:
113+
114+
`jsonschema.exceptions.SchemaError`
115+
116+
if the schema is invalid
104117
"""
105118

106119
def is_type(self, instance: Any, type: str) -> bool:
107120
"""
108121
Check if the instance is of the given (JSON Schema) type.
109122
110-
:type type: str
111-
:rtype: bool
112-
:raises: `jsonschema.exceptions.UnknownType` if ``type``
113-
is not a known type.
123+
Arguments:
124+
125+
instance:
126+
127+
the value to check
128+
129+
type:
130+
131+
the name of a known (JSON Schema) type
132+
133+
Returns:
134+
135+
whether the instance is of the given type
136+
137+
Raises:
138+
139+
`jsonschema.exceptions.UnknownType`
140+
141+
if ``type`` is not a known type
114142
"""
115143

116144
def is_valid(self, instance: Any) -> bool:
117145
"""
118146
Check if the instance is valid under the current `schema`.
119147
120-
:rtype: bool
148+
Returns:
149+
150+
whether the instance is valid or not
121151
122152
>>> schema = {"maxItems" : 2}
123153
>>> Draft202012Validator(schema).is_valid([2, 3, 4])
@@ -128,9 +158,6 @@ def iter_errors(self, instance: Any) -> Iterable[ValidationError]:
128158
r"""
129159
Lazily yield each of the validation errors in the given instance.
130160
131-
:rtype: an `collections.abc.Iterable` of
132-
`jsonschema.exceptions.ValidationError`\s
133-
134161
>>> schema = {
135162
... "type" : "array",
136163
... "items" : {"enum" : [1, 2, 3]},
@@ -147,8 +174,11 @@ def validate(self, instance: Any) -> None:
147174
"""
148175
Check if the instance is valid under the current `schema`.
149176
150-
:raises: `jsonschema.exceptions.ValidationError` if the
151-
instance is invalid
177+
Raises:
178+
179+
`jsonschema.exceptions.ValidationError`
180+
181+
if the instance is invalid
152182
153183
>>> schema = {"maxItems" : 2}
154184
>>> Draft202012Validator(schema).validate([2, 3, 4])

0 commit comments

Comments
 (0)