From a0395a7d501b9289c61a275a89df1c87a981c439 Mon Sep 17 00:00:00 2001 From: Serwan Asaad Date: Tue, 3 Dec 2024 21:44:00 +0100 Subject: [PATCH] Added docstring plus validation --- CHANGELOG.md | 1 + quam/core/quam_classes.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e672e1..cb76bec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## [Unreleased] ### Added +- Added `QuamBase.set_at_reference` to set a value at a reference - Added `string_reference.get_parent_reference` to get the parent reference of a string reference ## [0.3.8] diff --git a/quam/core/quam_classes.py b/quam/core/quam_classes.py index c05f3d6..4263965 100644 --- a/quam/core/quam_classes.py +++ b/quam/core/quam_classes.py @@ -548,6 +548,11 @@ def set_at_reference(self, attr: str, value: Any): Args: attr: The attribute to set the value at the reference of. value: The value to set. + + Raises: + ValueError: If the attribute is not a reference. + ValueError: If the reference is invalid, e.g. "#./" since it has no + attribute. """ raw_value = self.get_unreferenced_value(attr) if not string_reference.is_reference(raw_value): @@ -557,6 +562,12 @@ def set_at_reference(self, attr: str, value: Any): ) parent_reference, ref_attr = string_reference.split_reference(raw_value) + if not ref_attr: + raise ValueError( + f"Unsuccessful attempt to set the value at reference {raw_value} for " + f"attribute {attr} because the reference is invalid as it has no " + "attribute" + ) parent_obj = self._get_referenced_value(parent_reference) setattr(parent_obj, ref_attr, value)