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

fix instantiation of tuple list #24

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions quam/core/quam_instantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ def instantiate_attr(
)
if typing.get_origin(expected_type) == list:
expected_type = list
elif typing.get_origin(expected_type) == tuple:
instantiated_attr = tuple(instantiated_attr)
elif typing.get_origin(expected_type) == typing.Union:
instantiated_attr = attr_val
elif typing.get_origin(expected_type) == tuple:
Expand Down
11 changes: 10 additions & 1 deletion tests/instantiation/test_instantiation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from typing import List, Literal, Optional
from typing import List, Literal, Optional, Tuple

from quam.core import QuamRoot, QuamComponent, quam_dataclass
from quam.examples.superconducting_qubits.components import Transmon
Expand Down Expand Up @@ -317,3 +317,12 @@ def test_instance_attr_literal_fail():
attr_val=1,
expected_type=Literal["a", "b", "c"],
)


def test_isntantiate_tuple():
@quam_dataclass
class TestQuamTuple(QuamComponent):
tuple_val: Tuple[int, str]

obj = instantiate_quam_class(TestQuamTuple, {"tuple_val": [42, "hello"]})
assert obj.tuple_val == (42, "hello")