Skip to content

Validate scorer thresholds in process_py#489

Open
gaoflow wants to merge 1 commit into
rapidfuzz:mainfrom
gaoflow:fix-process-py-score-validation
Open

Validate scorer thresholds in process_py#489
gaoflow wants to merge 1 commit into
rapidfuzz:mainfrom
gaoflow:fix-process-py-score-validation

Conversation

@gaoflow

@gaoflow gaoflow commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

process_cpp validates score_cutoff and score_hint against the scorer's declared result range, while process_py silently accepts invalid values. This affects all five public process entry points: extractOne, extract, extract_iter, cdist, and cpdist. It is the process-layer divergence noted in #488.

Changes

  • Validate built-in scorer cutoffs and hints from their _RF_ScorerPy flags while leaving custom scorers unchanged.
  • Mirror the C++ conversions for float32 and size_t, including boundary rounding and exception behavior.
  • Cover both backends, all five APIs, upper/lower range errors, cutoff/hint, normalized and integer scorers, and conversion edge cases.

Testing

  • python -m pytest tests (507 passed)
  • black --check src/rapidfuzz/process_py.py tests/test_process.py
  • ruff check src/rapidfuzz/process_py.py tests/test_process.py
  • python tools/test_scorer_typing.py
  • python -m mypy tools/test_process_typing.py --warn-unused-ignores
  • python -m pyright -p tools/pyrightconfig.json tools/test_process_typing.py
  • Differential matrix: 300 backend/API/type/boundary combinations, no differences.

Mirror the C++ backend conversion and range checks for score_cutoff and score_hint across the extraction and matrix APIs. Preserve custom-scorer behavior and float32 cutoff semantics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant