Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de9483f

Browse files
authored
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
1 parent cb2d779 commit de9483f

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

jsonschema/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def by_relevance(weak=WEAK_MATCHES, strong=STRONG_MATCHES):
415415
def relevance(error):
416416
validator = error.validator
417417
return ( # prefer errors which are ...
418-
-len(error.path), # 'deeper' and thereby more specific
418+
-len(error.path), # 'higher up' (shorter path) and thereby more general
419419
error.path, # earlier (for sibling errors)
420420
validator not in weak, # for a non-low-priority keyword
421421
validator in strong, # for a high priority keyword

0 commit comments

Comments
 (0)