Repository: QCoDeS/Qcodes
Pull request #5446 (2023-10-19 12:44:43)

Fix incorrect step logic in validator.
The intent was that it should not be possible to set a float step size if any of the validators was an Int validator. That was however not correctly implemented.

Adding changelog directly to save a bit of time on towncrier since I am going to cut a new release just after merging this


Patch:
diff --git a/.github/workflows/darker.yaml b/.github/workflows/darker.yaml
index 4b52e25f5..b6796aede 100644
--- a/.github/workflows/darker.yaml
+++ b/.github/workflows/darker.yaml
@@ -21,5 +21,5 @@ jobs:
         with:
           options: "--check --diff"
           src: "./qcodes"
-          revision: "origin/master..."
+          revision: "origin/main..."
           version: "@e3c210b5c1b91400c3f317b2474c10ab23bec1cf"
diff --git a/docs/changes/0.41.1.rst b/docs/changes/0.41.1.rst
new file mode 100644
index 000000000..cdabb59e2
--- /dev/null
+++ b/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`)
diff --git a/docs/changes/index.rst b/docs/changes/index.rst
index 262f1ce98..f2401ec3c 100644
--- a/docs/changes/index.rst
+++ b/docs/changes/index.rst
@@ -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>
diff --git a/qcodes/parameters/parameter_base.py b/qcodes/parameters/parameter_base.py
index 06a99fe9b..7a8ddbcfd 100644
--- a/qcodes/parameters/parameter_base.py
+++ b/qcodes/parameters/parameter_base.py
@@ -838,7 +838,7 @@ class ParameterBase(MetadatableWithName):
             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")


Test patch:
diff --git a/qcodes/tests/parameter/test_validators.py b/qcodes/tests/parameter/test_validators.py
index e3e89da46..faee51975 100644
--- a/qcodes/tests/parameter/test_validators.py
+++ b/qcodes/tests/parameter/test_validators.py
@@ -3,7 +3,7 @@ import pytest
 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():
@@ -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