Skip to content

Commit

Permalink
Deprecate rarely used convenience methods on instrument class
Browse files Browse the repository at this point in the history
The aim is to reduce the number of ways in which the same operation can be performed
  • Loading branch information
jenshnielsen committed Jun 11, 2024
1 parent 698ce3d commit bcdadcb
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/qcodes/instrument/instrument_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,13 +631,21 @@ def _is_abstract(self) -> bool:
#
delegate_attr_dicts: ClassVar[list[str]] = ["parameters", "functions", "submodules"]

@deprecated(
"Use attributes directly on the instrument object instead.",
category=QCoDeSDeprecationWarning,
)
def __getitem__(self, key: str) -> Callable[..., Any] | Parameter:
"""Delegate instrument['name'] to parameter or function 'name'."""
try:
return self.parameters[key]
except KeyError:
return self.functions[key]

@deprecated(
"Call set directly on the parameter.",
category=QCoDeSDeprecationWarning,
)
def set(self, param_name: str, value: Any) -> None:
"""
Shortcut for setting a parameter from its name and new value.
Expand All @@ -648,6 +656,10 @@ def set(self, param_name: str, value: Any) -> None:
"""
self.parameters[param_name].set(value)

@deprecated(
"Call get directly on the parameter.",
category=QCoDeSDeprecationWarning,
)
def get(self, param_name: str) -> Any:
"""
Shortcut for getting a parameter from its name.
Expand All @@ -660,6 +672,10 @@ def get(self, param_name: str) -> Any:
"""
return self.parameters[param_name].get()

@deprecated(
"Call the function directly.",
category=QCoDeSDeprecationWarning,
)
def call(self, func_name: str, *args: Any) -> Any:
"""
Shortcut for calling a function from its name.
Expand Down

0 comments on commit bcdadcb

Please sign in to comment.