Skip to content

Commit d749f01

Browse files
authored
Merge pull request #7318 from jenshnielsen/jenshnielsen/deprecate_at_lower_level
Use a not visible warning in code that is not planned to be removed
2 parents c021097 + 9ce4481 commit d749f01

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The methods ``InstrumentBase.__getitem__``, ``InstrumentBase.get``, ``InstrumentBase.set``, ``InstrumentBase.call`` are now deprecated
2+
with a PendingDeprecationWarning rather than a QCoDeSDeprecationWarning. This better reflects the state where there is no plan to remove
3+
them but usage is discouraged. The PendingDeprecationWarning is not printed to console by default.

src/qcodes/instrument/instrument_base.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,10 @@ def _is_abstract(self) -> bool:
677677
delegate_attr_dicts: ClassVar[list[str]] = ["parameters", "functions", "submodules"]
678678

679679
@deprecated(
680-
"Use attributes directly on the instrument object instead.",
681-
category=QCoDeSDeprecationWarning,
680+
"Use of `__getitem__` is not recommended for new code. "
681+
"Use attributes directly on the instrument object instead. "
682+
"There is no plan to remove this functionality, but it is not recommended.",
683+
category=PendingDeprecationWarning,
682684
)
683685
def __getitem__(self, key: str) -> Callable[..., Any] | Parameter:
684686
"""
@@ -695,8 +697,10 @@ def __getitem__(self, key: str) -> Callable[..., Any] | Parameter:
695697
return self.functions[key]
696698

697699
@deprecated(
698-
"Call set directly on the parameter.",
699-
category=QCoDeSDeprecationWarning,
700+
"Use of `set` is not recommended for new code. "
701+
"Call set directly on the parameter instead. "
702+
"There is no plan to remove this functionality, but it is not recommended for new code.",
703+
category=PendingDeprecationWarning,
700704
)
701705
def set(self, param_name: str, value: Any) -> None:
702706
"""
@@ -714,8 +718,10 @@ def set(self, param_name: str, value: Any) -> None:
714718
self.parameters[param_name].set(value)
715719

716720
@deprecated(
717-
"Call get directly on the parameter.",
718-
category=QCoDeSDeprecationWarning,
721+
"Use of `get` is not recommended for new code. "
722+
"Call get directly on the parameter."
723+
"There is no plan to remove this functionality, but it is not recommended for new code.",
724+
category=PendingDeprecationWarning,
719725
)
720726
def get(self, param_name: str) -> Any:
721727
"""
@@ -734,8 +740,10 @@ def get(self, param_name: str) -> Any:
734740
return self.parameters[param_name].get()
735741

736742
@deprecated(
737-
"Call the function directly.",
738-
category=QCoDeSDeprecationWarning,
743+
"Use of `call` is not recommended for new code. "
744+
"Call the function directly instead. "
745+
"There is no plan to remove this functionality, but it is not recommended for new code.",
746+
category=PendingDeprecationWarning,
739747
)
740748
def call(self, func_name: str, *args: Any) -> Any:
741749
"""

tests/test_instrument.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
)
3131
from qcodes.metadatable import Metadatable
3232
from qcodes.parameters import Function, Parameter
33-
from qcodes.utils import QCoDeSDeprecationWarning
3433

3534
if TYPE_CHECKING:
3635
from collections.abc import Iterator
@@ -274,15 +273,15 @@ def test_add_remove_f_p(testdummy) -> None:
274273

275274
# test custom __get_attr__ for functions
276275
with pytest.warns(
277-
QCoDeSDeprecationWarning,
276+
PendingDeprecationWarning,
278277
match="Use attributes directly on the instrument object instead",
279278
):
280279
fcn = testdummy["function"]
281280
assert isinstance(fcn, Function)
282281
# by design, one gets the parameter if a function exists
283282
# and has same name
284283
with pytest.warns(
285-
QCoDeSDeprecationWarning,
284+
PendingDeprecationWarning,
286285
match="Use attributes directly on the instrument object instead",
287286
):
288287
dac1 = testdummy["dac1"]

0 commit comments

Comments
 (0)