maths/greatest_common_divisor: fix Python 3 except syntax#14932
Open
thejesh23 wants to merge 2 commits into
Open
maths/greatest_common_divisor: fix Python 3 except syntax#14932thejesh23 wants to merge 2 commits into
thejesh23 wants to merge 2 commits into
Conversation
`except IndexError, UnboundLocalError, ValueError:` is Python 2 syntax and raises SyntaxError under Python 3. The module currently fails to import at all, and downstream modules that depend on it (maths.least_common_multiple, maths.primelib) also fail with ImportError. Restore the parenthesised tuple form `except (IndexError, UnboundLocalError, ValueError):`, which was the correct form before a recent pre-commit autoupdate stripped the parentheses. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
for more information, see https://pre-commit.ci
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.
Describe your change:
Fixes #14929
maths/greatest_common_divisor.pycurrently fails to import under any Python 3 interpreter because line 76 uses the Python 2 formexcept A, B, C:instead ofexcept (A, B, C):. The regression was introduced by the pre-commit autoupdate in commit 840ca00, when the ruff bump tov0.15.4stripped the parentheses from the previously-correct form.This one-line change restores the parenthesised tuple form, which:
maths.least_common_multipleandmaths.primelib, which both import from it and are currently broken by the sameSyntaxError,The wider ruff regression affects several other files (see issue #14929 for the full list); those are being handled separately per the one-file-per-PR rule.
Verified locally with
python3.12 -c "import maths.greatest_common_divisor"andpython3.12 -m doctest maths/greatest_common_divisor.py -v(18/18 pass).Checklist: