diff --git a/src/qcodes/instrument/channel.py b/src/qcodes/instrument/channel.py index 3b774f1dc134..1c74e5f441de 100644 --- a/src/qcodes/instrument/channel.py +++ b/src/qcodes/instrument/channel.py @@ -5,6 +5,7 @@ import sys import warnings from collections.abc import Callable, Iterable, Iterator, MutableSequence, Sequence +from functools import cached_property from typing import TYPE_CHECKING, Any, Generic, Self, cast, overload from typing_extensions import TypeVar @@ -291,7 +292,7 @@ def __add__(self: Self, other: ChannelTuple) -> Self: def short_name(self) -> str: return self._name - @property + @cached_property def full_name(self) -> str: return "_".join(self.name_parts) diff --git a/src/qcodes/instrument/instrument_base.py b/src/qcodes/instrument/instrument_base.py index 52894a2e7284..2bb8771bcf8c 100644 --- a/src/qcodes/instrument/instrument_base.py +++ b/src/qcodes/instrument/instrument_base.py @@ -6,6 +6,7 @@ import logging import warnings from collections.abc import Callable, Mapping, Sequence +from functools import cached_property from typing import TYPE_CHECKING, Any, ClassVar, cast import numpy as np @@ -596,7 +597,7 @@ def name_parts(self) -> list[str]: """ return [self.short_name] - @property + @cached_property def full_name(self) -> str: """ Full name of the instrument. diff --git a/src/qcodes/metadatable/metadatable_base.py b/src/qcodes/metadatable/metadatable_base.py index a37897b4ee21..2f02bc95caa4 100644 --- a/src/qcodes/metadatable/metadatable_base.py +++ b/src/qcodes/metadatable/metadatable_base.py @@ -1,4 +1,5 @@ from abc import abstractmethod +from functools import cached_property from typing import TYPE_CHECKING, Any, final from qcodes.utils import deep_update @@ -79,7 +80,7 @@ def short_name(self) -> str: Name excluding name of any parent that this object is bound to. """ - @property + @cached_property @abstractmethod def full_name(self) -> str: """ diff --git a/src/qcodes/parameters/function.py b/src/qcodes/parameters/function.py index aab2420e1045..cc93e4ff996f 100644 --- a/src/qcodes/parameters/function.py +++ b/src/qcodes/parameters/function.py @@ -1,5 +1,6 @@ from __future__ import annotations +from functools import cached_property from typing import TYPE_CHECKING, Any from qcodes.metadatable import MetadatableWithName @@ -180,7 +181,7 @@ def short_name(self) -> str: """ return self.name - @property + @cached_property def full_name(self) -> str: """ Name of the function including the name of the instrument and diff --git a/src/qcodes/parameters/parameter_base.py b/src/qcodes/parameters/parameter_base.py index baba76c77fd2..319b6def8837 100644 --- a/src/qcodes/parameters/parameter_base.py +++ b/src/qcodes/parameters/parameter_base.py @@ -1014,7 +1014,7 @@ def short_name(self) -> str: full name refer to :meth:`full_name`.""" return self._short_name - @property + @cached_property def full_name(self) -> str: """ Name of the parameter including the name of the instrument and diff --git a/tests/common.py b/tests/common.py index 3d2ea62c3f11..8ed32f7bda2c 100644 --- a/tests/common.py +++ b/tests/common.py @@ -2,7 +2,7 @@ import cProfile import os -from functools import wraps +from functools import cached_property, wraps from time import sleep from typing import TYPE_CHECKING, Any, TypeVar @@ -159,6 +159,6 @@ def set(self, value: float) -> float: def short_name(self) -> str: return self.name - @property + @cached_property def full_name(self) -> str: return self.full_name