Skip to content

Commit

Permalink
Add warning to add_parameter when bind_to_instrument is False
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshnielsen committed Dec 16, 2024
1 parent 72d0be9 commit cbdc9bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/qcodes/instrument/instrument_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ def add_parameter(

bind_to_instrument = kwargs["bind_to_instrument"]

if bind_to_instrument is False:
warnings.warn(
f"Parameter {name} passed to `add_parameter` "
"on instrument {self.full_name} with `bind_to_instrument=False`. "
"This is not recommended as it results in inconsistent behavior. "
"To disable snapshotting of the parameter set `snapshot_exclude=True`."
)

try:
param = parameter_class(name=name, instrument=self, **kwargs)
except TypeError:
Expand Down
13 changes: 7 additions & 6 deletions tests/parameter/test_parameter_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ def test_parameter_registration_with_non_kwargs_passing_parameter(
def test_parameter_registration_bind_to_instrument_false(
dummy_attr_instr: DummyAttrInstrument,
) -> None:
dummy_attr_instr.add_parameter(
name="non_binding_parameter",
set_cmd=None,
get_cmd=None,
bind_to_instrument=False,
)
with pytest.warns(UserWarning, match="passed to `add_parameter`"):
dummy_attr_instr.add_parameter(
name="non_binding_parameter",
set_cmd=None,
get_cmd=None,
bind_to_instrument=False,
)
assert "non_binding_parameter" not in dummy_attr_instr.parameters.keys()

0 comments on commit cbdc9bf

Please sign in to comment.