@@ -155,24 +155,36 @@ a ``types`` argument on construction that specifies additional types, or which
155
155
can be used to specify a different set of Python types to map to a given JSON
156
156
type.
157
157
158
- For instance, JSON defines a ``number `` type, which can be validated with a
159
- schema such as ``{"type" : "number"} ``. By default, this will validate
160
- correctly for Python :class: `int `\s and :class: `float `\s . If you wanted to
161
- additionally validate :class: `decimal.Decimal ` objects, you'd use
158
+ ``jsonschema `` tries to be as general as possible by default. For instance,
159
+ JSON defines a ``number `` type, which can be validated with a schema such as
160
+ ``{"type" : "number"} ``. By default, this will validate correctly for instances
161
+ of Python :class: `number.Number `\s . This includes in particular :class: `int `\s
162
+ and :class: `float `\s , along with `decimal.Decimal ` objects, :class: `complex `
163
+ numbers etc. See the numbers _ module documentation for more details.
164
+
165
+ For most purposes, if you want to add additional types as being acceptible for
166
+ a validator, you should do so by inheriting from the relevant ``abc `` or by
167
+ registering the existing class with the ``abc ``. If this isn't an option, or if
168
+ you otherwise prefer not doing so, :class: `IValidator `\s have a ``types ``
169
+ argument that can be used to provide additional or new types.
162
170
163
171
.. code-block :: python
164
172
173
+ class MyInteger (object ):
174
+ ...
175
+
165
176
Draft3Validator(
166
177
schema = {" type" : " number" },
167
- types = {" number" : (int , float , decimal.Decimal )},
178
+ types = {" number" : (numbers.Number, MyInteger )},
168
179
)
169
180
170
181
The list of default Python types for each JSON type is available on each
171
182
validator in the :attr: `IValidator.DEFAULT_TYPES ` attribute. Note that you
172
183
need to specify all types to match if you override one of the existing JSON
173
- types, so you may want to access the set of default types to add it to the
174
- ones being appended .
184
+ types, so you may want to access the set of default types when specifying your
185
+ additional type .
175
186
187
+ .. numbers :: http://docs.python.org/3.3/library/numbers.html
176
188
177
189
.. _versioned-validators :
178
190
0 commit comments