Skip to content

Wrong comment in relevance function? #1325

Open
@mmarseu

Description

@mmarseu

When looking at the way jsonschema.exceptions.best_match works to figure out a way to better interpret jsonschema errors, I was mislead by what I believe to be a wrong comment.

return ( # prefer errors which are ...
-len(error.path), # 'deeper' and thereby more specific
error.path, # earlier (for sibling errors)

In line 412, you're saying errors which are deeper (i.e., longer path) are preferred but the code is actually doing the opposite. It prefers errors with shorter paths. Am I correct? This behavior would be in line with the documentation of the best_match function:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions