Skip to content

Fix SyntaxError and NameError in multiple files#14855

Closed
ArnavGarg7 wants to merge 2 commits into
TheAlgorithms:masterfrom
ArnavGarg7:fix-python3-syntax-errors-v2
Closed

Fix SyntaxError and NameError in multiple files#14855
ArnavGarg7 wants to merge 2 commits into
TheAlgorithms:masterfrom
ArnavGarg7:fix-python3-syntax-errors-v2

Conversation

@ArnavGarg7

Copy link
Copy Markdown

Describe your change:

This PR fixes multiple bugs that were preventing pytest from properly collecting and running tests due to SyntaxError and NameError exceptions during the import/collection phase.

  1. maths/matrix_exponentiation.py: Fixed a NameError where Matrix was referenced in its own class methods as a type hint before it was fully defined. Resolved this by adding from __future__ import annotations.
  2. web_programming/fetch_well_rx_price.py: Fixed a SyntaxError: multiple exception types must be parenthesized. The code was using Python 2 exception syntax (except httpx.HTTPError, ValueError:). Updated it to the correct Python 3 syntax (except (httpx.HTTPError, ValueError):).
  3. web_programming/instagram_crawler.py: Fixed an identical SyntaxError for multiple exception types (except json.decoder.JSONDecodeError, KeyError:). Updated it to except (json.decoder.JSONDecodeError, KeyError):.
  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

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 one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@ArnavGarg7 ArnavGarg7 requested a review from cclauss as a code owner June 24, 2026 12:40
Copilot AI review requested due to automatic review settings June 24, 2026 12:40
@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Jun 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to fix import/collection-time failures by addressing forward-reference type annotations in maths/matrix_exponentiation.py, but the PR description/title claim additional SyntaxError fixes in web_programming/ that are not present in the actual changeset.

Changes:

  • Add from __future__ import annotations to defer evaluation of Matrix type hints and avoid NameError during import.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1 to +4
"""Matrix Exponentiation"""

from __future__ import annotations

@cclauss

cclauss commented Jun 24, 2026

Copy link
Copy Markdown
Member

We only run on the current version of Python (3.14.6), so these changes are not needed.

@cclauss cclauss closed this Jun 24, 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 enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants