Repository navigation
Validate out-of-range score_cutoff in the pure Python fallback - #520
Open
draarivpatel-ui wants to merge 1 commit into
Open
draarivpatel-ui wants to merge 1 commit into
draarivpatel-ui wants to merge 1 commit into
Conversation
The C++ implementation rejects out-of-range score_cutoff values while the pure Python fallback silently accepted them, so code that runs with RAPIDFUZZ_IMPLEMENTATION=python or on PyPy failed with the default build: - negative cutoffs of integer metrics raise OverflowError in C++ but were silently accepted in the fallback - normalized scores and Jaro/JaroWinkler metrics raise TypeError in C++ for values outside 0.0 - 1.0 but were silently accepted in the fallback Validate score_cutoff in the fallback with the same errors as the C++ implementation. Fixes rapidfuzz#509
maxbachmann
reviewed
Nov 26, 2026
| prefix_len = common_prefix(s1, s2) | ||
| suffix_len = common_suffix(s1[prefix_len:], s2[prefix_len:]) | ||
| return (prefix_len, suffix_len) | ||
| def validate_score_cutoff_f64(score_cutoff, worst_score, optimal_score): |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #509.
For out-of-range
score_cutoffvalues the C++ implementation and the pure Python fallback behaved differently, so code that works withRAPIDFUZZ_IMPLEMENTATION=python(or on PyPy) failed with the default build:The fallback now validates
score_cutoffin the public metric functions with the same errors as the C++ implementation, mirroring theget_score_cutoff_f64/get_score_cutoff_size_tlogic incpp_common.pxd:distance/similarityof Hamming, Levenshtein, DamerauLevenshtein, OSA, LCSseq, Indel, Prefix, Postfix): negative cutoffs raiseOverflowError0.0 - 1.0raiseTypeErrorValid inputs are unaffected; coverage is limited to the distance metrics shown in the issue.