Conversation
… 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>
Argus reviewAuto-review is off for this repo. Tick the box below to run a review on this PR.
Estimated cost
Tip: you can also comment |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
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>
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.
Description
Fixes Issue #437:
loads('')raisesAttributeErrorinstead ofValidationError.When
openqasm3.parse('')is called with an empty string, the ANTLR parser returns a parse tree with nodes that haveNonefornode.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 anAttributeErrorthat was not being caught.This fix adds
AttributeErrorto the exception handling inloads(), converting it to aValidationErrorto be consistent with other invalid input cases.Changes
except AttributeErrorclause insrc/pyqasm/entrypoint.pyto catch the AttributeError raised byopenqasm3.parse()when given an empty string, and re-raise it asValidationError.Testing
Verified that:
pyqasm.loads('')now raisesValidationErrorinstead ofAttributeErrorRelated Issue
Fixes #437
This PR is submitted as part of the OpenQASM Quantum Software OSS contribution program.