Skip to content

[DUP - closed, see #446] - #445

Closed
Jah-yee wants to merge 3 commits into
qBraid:mainfrom
Jah-yee:main
Closed

Jah-yee wants to merge 3 commits into
qBraid:mainfrom
Jah-yee:main

Conversation

@Jah-yee

@Jah-yee Jah-yee commented Oct 3, 2026

Copy link
Copy Markdown

Description

Fixes Issue #437: loads('') raises AttributeError instead of ValidationError.

When openqasm3.parse('') is called with an empty string, the ANTLR parser returns a parse tree with nodes that have None for node.stop. The error 'NoneType' object has no attribute 'line' is raised from inside the parser when trying to build the AST span, and this bubbles up as an AttributeError that was not being caught.

This fix adds AttributeError to the exception handling in loads(), converting it to a ValidationError to be consistent with other invalid input cases.

Changes

  • Added except AttributeError clause in src/pyqasm/entrypoint.py to catch the AttributeError raised by openqasm3.parse() when given an empty string, and re-raise it as ValidationError.

Testing

Verified that:

  • pyqasm.loads('') now raises ValidationError instead of AttributeError
  • Valid QASM strings continue to work correctly

Related Issue

Fixes #437


This PR is submitted as part of the OpenQASM Quantum Software OSS contribution program.

… input

Fixes Issue qBraid#437: loads('') now raises ValidationError (consistent
with other invalid inputs) instead of AttributeError when openqasm3
parser encounters malformed/empty input and returns None for node.stop.line.

GH007: Jah-yee <jydu_seven@outlook.com>
@Jah-yee
Jah-yee requested a review from TheGupta2012 as a code owner October 3, 2026 23:23
@argus-eye

argus-eye Bot commented Oct 3, 2026

Copy link
Copy Markdown

Argus review

Auto-review is off for this repo. Tick the box below to run a review on this PR.

  • Trigger Argus review

Estimated cost

  • Files changed: 1
  • Diff lines (±): 2
  • Historical avg: ~350.5k tokens · ~$1.38 · across last 13 review(s)

Tip: you can also comment @argus-eye review at any time.

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: qBraid/pyqasm/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6884d7fb-c050-4aeb-8a48-4c3afa2d2350

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Fixes qBraid#437: loads('') now raises ValidationError instead of AttributeError.
When an extern function is called as a bare statement (not assigned to a
variable), pyqasm returned the raw FunctionCall node from
_visit_function_call. The openqasm3 printer's visit_FunctionCall does not
add a terminating semicolon; that is done by visit_ExpressionStatement via
_end_statement. This caused dumps() to emit extern call lines without
semicolons, making the output unparsable by openqasm3.parse.

Fix: wrap the extern FunctionCall in qasm3_ast.ExpressionStatement before
appending to the result list, so the printer correctly adds the semicolon.

Fixes qBraid#438.
Co-authored-by: Jah-yee <166608075+Jah-yee@users.noreply.github.com>
@Jah-yee Jah-yee closed this Oct 5, 2026
@Jah-yee Jah-yee changed the title fix: raise ValidationError instead of AttributeError for empty string in loads() [DUP - closed, see #446] Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

loads("") raises AttributeError instead of ValidationError

1 participant