Skip to content

Commit

Permalink
Merge pull request #5446 from jenshnielsen/fix_validator
Browse files Browse the repository at this point in the history
Fix incorrect step logic in validator.
  • Loading branch information
jenshnielsen committed Oct 19, 2023
2 parents b65a797 + eb2350b commit 9cad60d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/darker.yaml
Expand Up @@ -21,5 +21,5 @@ jobs:
with:
options: "--check --diff"
src: "./qcodes"
revision: "origin/master..."
revision: "origin/main..."
version: "@e3c210b5c1b91400c3f317b2474c10ab23bec1cf"
8 changes: 8 additions & 0 deletions docs/changes/0.41.1.rst
@@ -0,0 +1,8 @@
QCoDeS 0.41.1 (2023-10-19)
==========================

Improved:
---------

- Corrected a bug where non integer step sizes were incorrectly rejected
from parameters without integer validators. (:pr:`5446`)
1 change: 1 addition & 0 deletions docs/changes/index.rst
Expand Up @@ -3,6 +3,7 @@ Changelogs

.. toctree::
Unreleased <unreleased>
0.41.1 <0.41.1>
0.41.0 <0.41.0>
0.40.0 <0.40.0>
0.39.1 <0.39.1>
Expand Down
2 changes: 1 addition & 1 deletion qcodes/parameters/parameter_base.py
Expand Up @@ -838,7 +838,7 @@ def step(self, step: float | None) -> None:
self._step = None
elif step <= 0:
raise ValueError("step must be positive")
elif not all(isinstance(vals, Ints) for vals in self._vals) and not isinstance(
elif any(isinstance(vals, Ints) for vals in self._vals) and not isinstance(
step, int
):
raise TypeError("step must be a positive int for an Ints parameter")
Expand Down
18 changes: 17 additions & 1 deletion qcodes/tests/parameter/test_validators.py
Expand Up @@ -3,7 +3,7 @@
from hypothesis import given

from qcodes.parameters import Parameter
from qcodes.validators import Ints
from qcodes.validators import Ints, Numbers


def test_add_ints_validator_to_parameter():
Expand Down Expand Up @@ -187,3 +187,19 @@ def test_replace_vals():
p.remove_validator()
p.vals = None
assert len(p.validators) == 0


def test_validators_step_int() -> None:
# this parameter should allow step to be set as a float since the parameter is in it self a float
param = Parameter("a", get_cmd=False, set_cmd=False, vals=Numbers(0, 10))

param.step = 0.1
param.step = 1.0

param.add_validator(Ints(0, 10))

# but once we add an integer validator we no longer can set a step size as a float
with pytest.raises(
TypeError, match="step must be a positive int for an Ints parameter"
):
param.step = 0.1

0 comments on commit 9cad60d

Please sign in to comment.