@@ -303,8 +303,8 @@ instance. Each tree and child has a :attr:`~ErrorTree.errors` attribute, a
303
303
dict, that maps the failed validator to the corresponding validation error.
304
304
305
305
306
- best_match and by_relevance
307
- ---------------------------
306
+ best_match and relevance
307
+ ------------------------
308
308
309
309
The :func: `best_match ` function is a simple but useful function for attempting
310
310
to guess the most relevant error in a given bunch.
@@ -340,8 +340,11 @@ to guess the most relevant error in a given bunch.
340
340
different instances or schemas), since it won't produce sensical
341
341
output.
342
342
:argument callable key: the key to use when sorting errors. See
343
- :func: `by_relevance ` for more details (the default is to sort with the
344
- defaults of that function).
343
+ :attr: `relevance ` and transitively :func: `by_relevance ` for more
344
+ details (the default is to sort with the defaults of that function).
345
+ Changing the default is only useful if you want to change the function
346
+ that rates errors but still want the error context decension done by
347
+ this function.
345
348
:returns: the best matching error, or ``None `` if the iterable was empty
346
349
347
350
.. note::
@@ -350,22 +353,23 @@ to guess the most relevant error in a given bunch.
350
353
set of inputs from version to version if better heuristics are added.
351
354
352
355
353
- .. autofunction :: by_relevance
356
+ .. function :: relevance(validation_error)
354
357
355
- Create a key function that can be used to sort errors by relevance.
358
+ A key function that sorts errors based on heuristic relevance.
356
359
357
- If you want to sort a bunch of errors entirely, you can use this function
358
- to do so. Using the return value of this function as a key to e.g.
360
+ If you want to sort a bunch of errors entirely, you can use
361
+ this function to do so. Using this function as a key to e.g.
359
362
:func: `sorted ` or :func: `max ` will cause more relevant errors to be
360
363
considered greater than less relevant ones.
361
364
362
- :argument set weak: a collection of validators to consider to be "weak". If
363
- there are two errors at the same level of the instance and one is in
364
- the set of weak validators, the other error will take priority. By
365
- default, :validator: `anyOf ` and :validator: `oneOf ` are considered weak
366
- validators and will be superceded by other same-level validation
367
- errors.
368
- :argument set strong: a collection of validators to consider to be "strong"
365
+ Within the different validators that can fail, this function
366
+ considers :validator: `anyOf ` and :validator: `oneOf ` to be *weak *
367
+ validation errors, and will sort them lower than other validators at
368
+ the same level in the instance.
369
+
370
+ If you want to change the set of weak [or strong] validators you can create
371
+ a custom version of this function with :func: `by_relevance ` and provide a
372
+ different set of each.
369
373
370
374
.. doctest::
371
375
@@ -383,6 +387,19 @@ to guess the most relevant error in a given bunch.
383
387
>>> errors = Draft4Validator(schema).iter_errors(instance)
384
388
>>> [
385
389
... e.path[-1]
386
- ... for e in sorted(errors, key=exceptions.by_relevance() )
390
+ ... for e in sorted(errors, key=exceptions.relevance )
387
391
... ]
388
392
['home', 'name']
393
+
394
+
395
+ .. autofunction:: by_relevance
396
+
397
+ Create a key function that can be used to sort errors by relevance.
398
+
399
+ :argument set weak: a collection of validators to consider to be "weak". If
400
+ there are two errors at the same level of the instance and one is in
401
+ the set of weak validators, the other error will take priority. By
402
+ default, :validator: `anyOf ` and :validator: `oneOf ` are considered weak
403
+ validators and will be superceded by other same-level validation
404
+ errors.
405
+ :argument set strong: a collection of validators to consider to be "strong"
0 commit comments