-
Notifications
You must be signed in to change notification settings - Fork 320
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
add vals property and setter to delegate_parameter #6817
Changes from all commits
4207da0
b1db7ab
734c585
1ad1a77
1e5adfa
e5298b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add vals property and @vals.setter to qcodes.parameters.delegate_parameter.DelegateParameter to propagate the Validator from source to DelegateParameter. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
from collections.abc import Sequence | ||
from datetime import datetime | ||
|
||
from qcodes.validators import Validator | ||
|
||
from .parameter_base import ParamDataType, ParamRawDataType | ||
|
||
|
||
|
@@ -171,9 +173,11 @@ def __init__( | |
|
||
initial_cache_value = kwargs.pop("initial_cache_value", None) | ||
self.source = source | ||
self._vals_override: Validator | None = None | ||
super().__init__(name, *args, **kwargs) | ||
self.label = kwargs.get("label", None) | ||
self.unit = kwargs.get("unit", None) | ||
self.vals = kwargs.get("vals", None) | ||
|
||
# Hack While we inherit the settable status from the parent parameter | ||
# we do allow param.set_to to temporary override _settable in a | ||
|
@@ -223,6 +227,23 @@ def unit(self) -> str: | |
def unit(self, unit: str | None) -> None: | ||
self._unit_override = unit | ||
|
||
@property | ||
def vals(self) -> Validator | None: | ||
""" | ||
The validator of the parameter. Read from source if not explicitly overwritten. | ||
Set to None to disable overwrite. | ||
""" | ||
if self._vals_override is not None: | ||
return self._vals_override | ||
elif self.source is not None: | ||
return self.source.vals | ||
else: | ||
return None | ||
|
||
@vals.setter | ||
def vals(self, vals: Validator | None) -> None: | ||
self._vals_override = vals | ||
|
||
@property | ||
def label(self) -> str: | ||
""" | ||
|
@@ -314,3 +335,5 @@ def validate(self, value: ParamDataType) -> None: | |
super().validate(value) | ||
if self.source is not None: | ||
self.source.validate(self._from_value_to_raw_value(value)) | ||
if self.vals is not None: | ||
self.vals.validate(value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this necessary. Will the call to super.validate above not do the same? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it will only validate with the validator on the source, so it will not enforce the validator on the delegate parameter without this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The additional cases I added in the tests show this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see what is going on. the call to validator in the base class will use all validators stored as part of _vals. Since this pr prevents you from adding any validator to that list it will always be empty so that line does nothing on this pr. However prior to this pr adding a validator to the DelegateParameter would cause it to be added to the parameters _vals list and used. This makes me suspect that the tests as is would also pass on main. #6832 seems to confirm this too so I am not completely sure if this pr is required |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ParameterBase supports multiple validators via the add_validator etc logic. We need to consider if we want to support that here too.