From f14c77dd2dc1b1282f5bd1635a7d635106759a7c Mon Sep 17 00:00:00 2001 From: Serwan Asaad Date: Tue, 2 Apr 2024 09:43:25 +0200 Subject: [PATCH] fix instantiation of tuple list --- quam/core/quam_instantiation.py | 2 ++ tests/instantiation/test_instantiation.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/quam/core/quam_instantiation.py b/quam/core/quam_instantiation.py index 613c2641..7f0b0e01 100644 --- a/quam/core/quam_instantiation.py +++ b/quam/core/quam_instantiation.py @@ -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: diff --git a/tests/instantiation/test_instantiation.py b/tests/instantiation/test_instantiation.py index 40b14fab..433740e4 100644 --- a/tests/instantiation/test_instantiation.py +++ b/tests/instantiation/test_instantiation.py @@ -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 @@ -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") \ No newline at end of file