Fix version parsing NameError and older Python syntax compatibility#6318
Conversation
There was a problem hiding this comment.
Code Review
This pull request resolves a bug in unsloth/import_fixes.py where an undefined variable e was referenced when raising an exception, replacing it with a clear ValueError. Additionally, it corrects tensor indexing in unsloth/kernels/moe/tests/common.py by removing the unpacking operator * from bad_idxs. No review comments were provided, so there is no feedback to address.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Imagineer99
left a comment
There was a problem hiding this comment.
Tested and works as expected. Verified the Python 3.9/3.10 syntax issue is fixed, the changed tensor indexing preserves behavior, and invalid version parsing now reports the intended underlying error instead of the secondary NameError. Merging.

I was running some static analysis on the codebase and found a couple of minor but critical bugs which are:
Fixed a crash in
import_fixes.py:In
Version(), if an invalid version string was passed, the exception handler was trying to raiseException(str(e)). However, the variableewas unbound, which would cause a secondaryNameErrorand hide the actual parsing issue. I replaced this with a cleanValueError(f"Could not parse version: {version}").Fixed a Python < 3.11 SyntaxError in
kernels/moe/tests/common.py:In
assert_indx_equal/ the MoE tests, there was an unpacked tuple inside an array index (ref[*bad_idxs]). This syntax isn't supported in Python 3.9/3.10 and causes a hard syntax error. I removed the asterisk to use standard indexing (ref[bad_idxs]), which restores compatibility across all supported Python versions.