Skip to content

Honor falsey callable processors in cdist and cpdist - #505

Merged
maxbachmann merged 3 commits into
rapidfuzz:mainfrom
manav4u:fix-falsey-matrix-processors
Nov 9, 2026
Merged

maxbachmann merged 3 commits into
rapidfuzz:mainfrom
manav4u:fix-falsey-matrix-processors

Conversation

@manav4u

@manav4u manav4u commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Developed with AI assistance.

cdist and cpdist can skip a callable processor when its __bool__ returns False or its __len__ returns zero. For example, a falsey callable that lowercases its input gives a score of 0 for ['A'] against ['a'], rather than 100. A callable that rejects truth-value testing also raises before preprocessing.

Check processor identity rather than its truth value in the Python matrix functions and the Cython matrix preprocessing helpers. Preserve literal False as a no-preprocessing sentinel in native cdist/cpdist and Python cpdist. Python cdist previously raised TypeError for processor=False; it now treats that sentinel consistently with the other matrix paths. The current documented API is callable or None, but this patch keeps the accepted legacy behavior rather than removing it while fixing callables.

Tests cover both backends, built-in and custom scorers, false __bool__, zero __len__, a truth-value check that raises, and the symmetric cdist path with a missing value. Compatibility controls cover None, literal False and an ordinary callable.

Local validation on Python 3.12:

  • 27 of the 30 callable regression cases fail on the unmodified pairwise implementation; all 30 pass with this change.
  • Of the 24 compatibility controls, 22 pass on the base. The two base failures cover the explicitly described Python cdist(False) behavior change. All 24 pass with this change.
  • Native extensions built from the current checkout: 533 tests pass.
  • Forced Python scorer selection: 530 tests pass, with three existing extraction exception tests failing. Those same three failures reproduce with the unmodified Python process implementation.
  • Black 25.1.0, Ruff 0.11.5 and git diff --check pass for the changed Python files.

@maxbachmann
maxbachmann merged commit f010090 into rapidfuzz:main Nov 9, 2026
@maxbachmann

Copy link
Copy Markdown
Member

Thanks for the contribution

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.

2 participants