Skip to content

fix: parenthesize multiple exception types for Python 3 compatibility - #14989

Closed
zeeshanzzz788 wants to merge 2 commits into
TheAlgorithms:masterfrom
zeeshanzzz788:fix/parenthesize-multiple-exception-types
Closed

fix: parenthesize multiple exception types for Python 3 compatibility#14989
zeeshanzzz788 wants to merge 2 commits into
TheAlgorithms:masterfrom
zeeshanzzz788:fix/parenthesize-multiple-exception-types

Conversation

@zeeshanzzz788

Copy link
Copy Markdown

Describe your change:

Several modules currently use invalid Python 3 syntax:

except IndexError, TypeError:

This is Python 2 syntax. In Python 3, multiple exception types must be parenthesized:

except (IndexError, TypeError):

Without the parentheses, importing these modules fails immediately with:

SyntaxError: multiple exception types must be parenthesized

This was introduced by a ruff rewrite (see discussion on #14929). This PR restores valid Python 3 syntax in all 12 affected files, not only maths/greatest_common_divisor.py.

Files fixed:

  • maths/greatest_common_divisor.py
  • digital_image_processing/filters/local_binary_pattern.py
  • divide_and_conquer/convex_hull.py
  • dynamic_programming/catalan_numbers.py
  • project_euler/problem_002/sol4.py
  • project_euler/problem_003/sol1.py
  • project_euler/problem_003/sol2.py
  • project_euler/problem_003/sol3.py
  • project_euler/problem_005/sol1.py
  • project_euler/problem_007/sol2.py
  • web_programming/fetch_well_rx_price.py
  • web_programming/instagram_crawler.py

Verification:

  • Each file now parses successfully with ast.parse
  • python3 -m doctest maths/greatest_common_divisor.py — 18 passed
  • Imports of fixed modules succeed again

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes existing Python algorithm files (no new algorithm files this PR).
  • All new Python files are placed inside an existing directory.
  • All filenames are based on the type of algorithm but are also easy to understand, with no capital letters or special characters other than underscores.
  • All functions and variable names follow Python naming conventions and have descriptive names.
  • All functions have type hints.
  • All functions and classes have a docstring explaining what they do.
  • If a function returns a value, it has a return type hint.
  • All functions handle flawed inputs as described in CONTRIBUTING.md.
  • All algorithms raise Python exceptions instead of printing errors.
  • All new tests pass local test suite.
  • All pre-commit checks pass / I have avoided adding modules that require pre-commit hooks.
  • I will follow up to the PR comments in a timely manner.

except A, B: is Python 2 syntax and raises SyntaxError on Python 3.
Restore the parenthesized form except (A, B): in all modules broken by
a ruff rewrite so they import and run again.

Fixes TheAlgorithms#14929
@zeeshanzzz788
zeeshanzzz788 requested a review from cclauss as a code owner August 2, 2026 01:58
@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Aug 2, 2026
@cclauss

cclauss commented Aug 2, 2026

Copy link
Copy Markdown
Member

@cclauss cclauss closed this Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SyntaxError in maths/greatest_common_divisor.py — invalid Python 3 except clause

2 participants