From e0b5c5586d1c7726c58680370b47619b5c5d2ebd Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Thu, 10 Feb 2022 06:56:26 +0100 Subject: [PATCH 1/6] remove redundant typecast --- .../drivers/NationalInstruments/Switch.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/qcodes_contrib_drivers/drivers/NationalInstruments/Switch.py b/qcodes_contrib_drivers/drivers/NationalInstruments/Switch.py index 4cdc4449f..500ed8126 100644 --- a/qcodes_contrib_drivers/drivers/NationalInstruments/Switch.py +++ b/qcodes_contrib_drivers/drivers/NationalInstruments/Switch.py @@ -1,9 +1,8 @@ import logging -from typing import Optional, Dict, List, cast +from typing import Dict, List, Optional, cast -from qcodes import Instrument, InstrumentChannel, ChannelList - -from niswitch import Session, PathCapability +from niswitch import PathCapability, Session +from qcodes import ChannelList, Instrument, InstrumentChannel logger = logging.getLogger(__name__) @@ -159,5 +158,5 @@ def disconnect_from_all(self) -> None: Disconnect this channel from all channels it is connected to. """ while len(self.connection_list) > 0: - ch = cast(InstrumentChannel, self.connection_list[0]) + ch = self.connection_list[0] self.disconnect_from(ch) From 422d63164e727a24b6c6b11d5d0b70844f8fadc1 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Thu, 10 Feb 2022 07:19:08 +0100 Subject: [PATCH 2/6] QDac2 adapt signature to what is actually returned --- qcodes_contrib_drivers/drivers/QDevil/QDAC2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qcodes_contrib_drivers/drivers/QDevil/QDAC2.py b/qcodes_contrib_drivers/drivers/QDevil/QDAC2.py index 3e0912286..6e577706b 100644 --- a/qcodes_contrib_drivers/drivers/QDevil/QDAC2.py +++ b/qcodes_contrib_drivers/drivers/QDevil/QDAC2.py @@ -1554,14 +1554,14 @@ def __exit__(self, exc_type, exc_val, exc_tb): # Let Arrangement take care of freeing triggers return False - def actual_values_V(self, gate: str) -> Sequence[float]: + def actual_values_V(self, gate: str) -> np.ndarray: """The corrected values that would actually be sent to the gate Args: gate (str): Name of gate Returns: - Sequence[float]: Corrected voltages + np.ndarray: Corrected voltages """ index = self._arrangement._gate_index(gate) return self._sweep[:, index] From 7af3a3233c5d7d531360c0db0b782738e8435084 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Thu, 10 Feb 2022 07:29:20 +0100 Subject: [PATCH 3/6] handle that newer versions of qcodes does not register broken instruments --- .../tests/QDevil/test_sim_qdac2_init.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/qcodes_contrib_drivers/tests/QDevil/test_sim_qdac2_init.py b/qcodes_contrib_drivers/tests/QDevil/test_sim_qdac2_init.py index e2a3817c9..2a5470d0e 100644 --- a/qcodes_contrib_drivers/tests/QDevil/test_sim_qdac2_init.py +++ b/qcodes_contrib_drivers/tests/QDevil/test_sim_qdac2_init.py @@ -13,8 +13,11 @@ def test_refuse_wrong_model(): # ----------------------------------------------------------------------- assert 'Unknown model' in repr(error) # Circumvent Instrument not handling exceptions in constructor. - Instrument._all_instruments.pop(wrong_instrument) - + # In qcodes < 0.32 + try: + Instrument._all_instruments.pop(wrong_instrument) + except KeyError: + pass def test_refuse_incompatible_firmware(): # ----------------------------------------------------------------------- @@ -23,4 +26,8 @@ def test_refuse_incompatible_firmware(): # ----------------------------------------------------------------------- assert 'Incompatible firmware' in repr(error) # Circumvent Instrument not handling exceptions in constructor. - Instrument._all_instruments.pop('qdac') + # In qcodes < 0.32 + try: + Instrument._all_instruments.pop('qdac') + except KeyError: + pass From 90b17edc30bc4c849a1872d8b5b71f4174fbf949 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Thu, 10 Feb 2022 07:50:11 +0100 Subject: [PATCH 4/6] disable m4i warning --- qcodes_contrib_drivers/drivers/Spectrum/M4i.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qcodes_contrib_drivers/drivers/Spectrum/M4i.py b/qcodes_contrib_drivers/drivers/Spectrum/M4i.py index a4c590854..8c0810060 100644 --- a/qcodes_contrib_drivers/drivers/Spectrum/M4i.py +++ b/qcodes_contrib_drivers/drivers/Spectrum/M4i.py @@ -988,7 +988,9 @@ def _transfer_buffer_numpy(self, memsize: int, numch: int, bytes_per_sample=2) - raise Exception(f'Error transferring data: {_errormsg_dict[res]} (0x{res:04x})') # convert buffer to numpy array - output = np.frombuffer(data_buffer, dtype=sample_ctype) + # this does not typecheck with numpy 1.22 should be updated + # by someone with access to test on the real data. + output = np.frombuffer(data_buffer, dtype=sample_ctype) # type: ignore[call-overload] return output From 1640daf879b4ac3ddd1e67b352949ac7c6b47827 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Thu, 10 Feb 2022 07:50:27 +0100 Subject: [PATCH 5/6] show mypy errors --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 56849a89c..326ffea44 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,6 +46,7 @@ show_column_numbers = True warn_unused_ignores = True warn_unused_configs = True warn_redundant_casts = True +show_error_codes = True [mypy-qcodes_contrib_drivers._version] ignore_errors = True From 31430f412ef2fc5465ea9876f8072063684c3bfe Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Thu, 10 Feb 2022 07:50:48 +0100 Subject: [PATCH 6/6] disable mypy on 3.7 --- .github/workflows/pytest.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index bfab15978..5624ec0dc 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -68,6 +68,7 @@ jobs: pip install . - name: Run Mypy run: mypy qcodes_contrib_drivers + if: matrix.python-version != '3.7' - name: Run tests run: | pytest --cov=qcodes_contrib_drivers --cov-report xml --cov-config=setup.cfg qcodes_contrib_drivers