Skip to content

Commit

Permalink
Merge pull request #24 from qua-platform/fix/tuple-instantiation
Browse files Browse the repository at this point in the history
fix instantiation of tuple list
  • Loading branch information
nulinspiratie authored Apr 2, 2024
2 parents 6f89902 + f14c77d commit 4a67d0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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")

0 comments on commit 4a67d0b

Please sign in to comment.