Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #6211 #6212

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/changes/0.46.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ Breaking Changes:
- It is now considered unsupported to modify the `parameters` attribute of an instrument or instrument module after it has been created.
To remove a parameter from an instrument use the `remove_parameter` method. (:pr:`6174`)

- InstrumentBase.add_parameter will now error if an attribute of the same name as the parameter added already exists. This
is similar to how it would error if a parameter of the same name existed. (:pr:`6174`)
- InstrumentBase.add_parameter will now error if an attribute of the same name as the parameter added already exists and
this attribute is an instance of `ParameterBase`. This is to prevent issues where a parameter is partially
overwritten by a new parameter. To remove the existing Parameter use the new `instrument.remove_parameter`` method.
If the attribute is not a ParameterBase this will instead warn. It is the intention that this becomes an error in the future.
(:pr:`6174`) (:pr:`6211`)


Improved:
Expand Down
9 changes: 7 additions & 2 deletions src/qcodes/parameters/parameter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,14 @@ def __init__(
)
if existing_parameter is None:
existing_attribute = getattr(instrument, name, None)
if existing_attribute is not None:
if isinstance(existing_attribute, ParameterBase):
raise KeyError(
f"Parameter {name} overrides an attribute of the same name on instrument {instrument}"
f"Duplicate parameter name {name} on instrument {instrument}"
)
elif existing_attribute is not None:
warnings.warn(
f"Parameter {name} overrides an attribute of the same name on instrument {instrument} "
"This will be an error in the future.",
)

instrument.parameters[name] = self
Expand Down
5 changes: 2 additions & 3 deletions tests/parameter/test_parameter_override.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@ def __init__(self, name, **kwargs):
def test_overriding_parameter_attribute_with_parameter_raises():
with pytest.raises(
KeyError,
match="Parameter voltage overrides an attribute of the same name on instrument",
match="Duplicate parameter name voltage on instrument",
):
DummyOverrideInstr("my_instr")


def test_overriding_attribute_with_parameter_raises():
with pytest.raises(
KeyError,
with pytest.warns(
match="Parameter voltage overrides an attribute of the same name on instrument",
):
DummyParameterIsAttrInstr("my_instr")
Expand Down
Loading