OpenQuizz
Une application de gestion des contenus pédagogiques
jsonschema.exceptions Namespace Reference

Data Structures

class  _Error
 
class  ErrorTree
 
class  FormatError
 
class  RefResolutionError
 
class  SchemaError
 
class  UndefinedTypeCheck
 
class  UnknownType
 
class  ValidationError
 

Functions

def by_relevance (weak=WEAK_MATCHES, strong=STRONG_MATCHES)
 
def best_match (errors, key=relevance)
 

Variables

 WEAK_MATCHES
 
 STRONG_MATCHES
 
 relevance
 

Detailed Description

Validation errors, and some surrounding helpers.

Function Documentation

◆ best_match()

def jsonschema.exceptions.best_match (   errors,
  key = relevance 
)
Try to find an error that appears to be the best match among given errors.

In general, errors that are higher up in the instance (i.e. for which
`ValidationError.path` is shorter) are considered better matches,
since they indicate "more" is wrong with the instance.

If the resulting match is either :validator:`oneOf` or :validator:`anyOf`,
the *opposite* assumption is made -- i.e. the deepest error is picked,
since these validators only need to match once, and any other errors may
not be relevant.

Arguments:
    errors (collections.Iterable):

        the errors to select from. Do not provide a mixture of
        errors from different validation attempts (i.e. from
        different instances or schemas), since it won't produce
        sensical output.

    key (collections.Callable):

        the key to use when sorting errors. See `relevance` and
        transitively `by_relevance` for more details (the default is
        to sort with the defaults of that function). Changing the
        default is only useful if you want to change the function
        that rates errors but still want the error context descent
        done by this function.

Returns:
    the best matching error, or ``None`` if the iterable was empty

.. note::

    This function is a heuristic. Its return value may change for a given
    set of inputs from version to version if better heuristics are added.

◆ by_relevance()

def jsonschema.exceptions.by_relevance (   weak = WEAK_MATCHES,
  strong = STRONG_MATCHES 
)
Create a key function that can be used to sort errors by relevance.

Arguments:
    weak (set):
        a collection of validator names to consider to be "weak".
        If there are two errors at the same level of the instance
        and one is in the set of weak validator names, the other
        error will take priority. By default, :validator:`anyOf` and
        :validator:`oneOf` are considered weak validators and will
        be superseded by other same-level validation errors.

    strong (set):
        a collection of validator names to consider to be "strong"

Variable Documentation

◆ relevance

relevance

◆ STRONG_MATCHES

STRONG_MATCHES

◆ WEAK_MATCHES

WEAK_MATCHES