Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be explicit about openqasm3.ast imports #34

Merged
merged 3 commits into from
Oct 1, 2024
Merged

Conversation

braised-babbage
Copy link
Collaborator

@braised-babbage braised-babbage commented Sep 9, 2024

This makes imports from openqasm3.ast explicit, and does not import CalibrationStatement or CalibrationDefinition. These definitions were previously shadowed by subsequent entries in openpulse.ast, but this causes a problem for mypy, since the field types of the shadowing definitions disagree with the original field annotations.

For example, with the previous implementation, the following program would fail to type check

from openpulse.ast import CalibrationDefinition, CalibrationStatement

def foo(stmt: CalibrationDefinition):
    stmt.body = []

The mypy error is

mypy example.py
example.py:4: error: Incompatible types in assignment (expression has type "list[Never]", variable has type "str")  [assignment]
Found 1 error in 1 file (checked 1 source file)

The variable has type "str" comes from the openqasm3.ast.CalibrationDefinition, which does use str for the body field.

This closes #35

Copy link
Contributor

@hodgestar hodgestar left a comment

Choose a reason for hiding this comment

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

Definitely better to have explicit imports.

@braised-babbage braised-babbage merged commit db7bf66 into main Oct 1, 2024
11 checks passed
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.

Openpulse AST definitions shadow OpenQASM AST definitions with incompatible types
2 participants