Fix Python 3.12 compatibility by updating Cython template function signatures #1
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.
This PR fixes compilation failures on Python 3.12 by updating the Cython template to use modern function signatures compatible with newer Cython versions.
Problem
The current build fails on Python 3.12 with errors like:
This happens because modern Cython versions (3.1+) are stricter about exception handling in
nogilfunctions and generate Python 3.12-compatible C code that expectsnoexceptqualifiers.Solution
Updated three comparison functions in
lightfm/_lightfm_fast.pyx.templateto include thenoexceptqualifier:reverse_pair_compareint_compareflt_compareThese functions are used with
qsort()andbsearch()from the C standard library, which expect non-throwing comparison functions.Changes
Testing
Impact
This minimal change enables LightFM to build and run on Python 3.12 environments, including modern Databricks clusters, without requiring users to downgrade their Python runtime.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.