From de9483f2027f3fc2fa765e03d1f582aa6d5d913e Mon Sep 17 00:00:00 2001 From: Padmashree S S Date: Wed, 7 Jan 2026 18:10:24 +0530 Subject: [PATCH 1/2] docs: Fix misleading comment in relevance function The comment in the relevance() function incorrectly suggested that -len(error.path) prefers 'deeper' errors. In reality, this logic prioritizes errors with shorter paths (higher up in the instance). Updated the comment to accurately reflect that shorter paths are preferred for general validation errors, which aligns with the actual code behavior and official documentation for best_match. Closes #1325 --- jsonschema/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py index d955e356..d89e1776 100644 --- a/jsonschema/exceptions.py +++ b/jsonschema/exceptions.py @@ -415,7 +415,7 @@ def by_relevance(weak=WEAK_MATCHES, strong=STRONG_MATCHES): def relevance(error): validator = error.validator return ( # prefer errors which are ... - -len(error.path), # 'deeper' and thereby more specific + -len(error.path), # 'higher up' (shorter path) and thereby more general error.path, # earlier (for sibling errors) validator not in weak, # for a non-low-priority keyword validator in strong, # for a high priority keyword From 0e5655c3884c1df030287e224f8fc1eddc4fd636 Mon Sep 17 00:00:00 2001 From: Padmashree S S Date: Wed, 7 Jan 2026 19:44:34 +0530 Subject: [PATCH 2/2] Shortend the comment --- jsonschema/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py index d89e1776..2e5d4ca0 100644 --- a/jsonschema/exceptions.py +++ b/jsonschema/exceptions.py @@ -415,7 +415,7 @@ def by_relevance(weak=WEAK_MATCHES, strong=STRONG_MATCHES): def relevance(error): validator = error.validator return ( # prefer errors which are ... - -len(error.path), # 'higher up' (shorter path) and thereby more general + -len(error.path), # shorter path thereby more general error.path, # earlier (for sibling errors) validator not in weak, # for a non-low-priority keyword validator in strong, # for a high priority keyword