Skip to content

Improve best_match when used with applicators #1250

Closed
@Julian

Description

@Julian

Applicators have poor best matched errors in some cases even when there is only a single schema within the applicator!

A reproducer is:

from jsonschema import Draft202012Validator as Validator, exceptions

instance = [12, 12]

for applicator in "anyOf", "oneOf":
    # Should match {"items": {"const": 37}}
    single = {applicator: [{"items": {"const": 37}}]}
    error = exceptions.best_match(Validator(single).iter_errors(instance))
    print(single, "\n\n", error)

    # Should match {"items": {"const": 37}} due to type matching
    multiple = {applicator: [{"type": "object"}, {"items": {"const": 37}}]}
    error = exceptions.best_match(Validator(multiple).iter_errors(instance))
    print(multiple, "\n\n", error)

    # Should probably? match {"items": {"const": 37}} due to giving False low priority in any/oneOf
    multiple_false = {applicator: [False, {"items": {"const": 37}}]}
    error = exceptions.best_match(Validator(multiple_false).iter_errors(instance))
    print(multiple_false, "\n\n", error)

where there seem to be 3 related but separate issues.

#1002 is likely related if not the same, but these examples are probably more minimized. We should recheck that issue when fixing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementSome new desired functionalityError ReportingIssues related to clearer or more robust validation error reporting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions